mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
Merge pull request #2092 from notiant/patch-20
Add queue for Bluetooth auto-connect
This commit is contained in:
@@ -80,7 +80,7 @@ Item {
|
||||
}
|
||||
|
||||
let rateText = BatteryService.getRateText(selectedDevice);
|
||||
if (rateText) {
|
||||
if (!isPluggedIn && rateText) {
|
||||
const colonIdx = rateText.indexOf(":");
|
||||
if (colonIdx >= 0) {
|
||||
rows.push([rateText.substring(0, colonIdx).trim(), rateText.substring(colonIdx + 1).trim()]);
|
||||
|
||||
@@ -669,17 +669,10 @@ Item {
|
||||
pointSize: Style.fontSizeXS
|
||||
color: BluetoothService.getDeviceAutoConnect(modelData.address) ? Color.mPrimary : Color.mOnSurface
|
||||
Layout.alignment: Qt.AlignVCenter
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onEntered: TooltipService.show(parent, I18n.tr("tooltips.auto-connect"))
|
||||
onExited: TooltipService.hide()
|
||||
}
|
||||
}
|
||||
|
||||
NText {
|
||||
text: I18n.tr("common.auto-connect") + " " + (BluetoothService.getDeviceAutoConnect(modelData.address) ? I18n.tr("common.enabled") : I18n.tr("common.disabled"))
|
||||
text: I18n.tr("common.auto-connect")
|
||||
pointSize: Style.fontSizeXS
|
||||
color: BluetoothService.getDeviceAutoConnect(modelData.address) ? Color.mOnSurface : Color.mOnSurfaceVariant
|
||||
Layout.fillWidth: true
|
||||
@@ -689,7 +682,7 @@ Item {
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onEntered: TooltipService.show(parent, I18n.tr("tooltips.auto-connect"))
|
||||
onEntered: TooltipService.show(parent, BluetoothService.getDeviceAutoConnect(modelData.address) ? I18n.tr("tooltips.bluetooth-auto-connect-on") : I18n.tr("tooltips.bluetooth-auto-connect-off"))
|
||||
onExited: TooltipService.hide()
|
||||
onClicked: BluetoothService.setDeviceAutoConnect(modelData, !BluetoothService.getDeviceAutoConnect(modelData.address))
|
||||
}
|
||||
|
||||
@@ -64,9 +64,10 @@ Singleton {
|
||||
property int connectAttempts: 5
|
||||
property int connectRetryIntervalMs: 2000
|
||||
|
||||
// Internal: temporarily pause discovery during pair/connect to reduce HCI churn
|
||||
// Internal variables
|
||||
property bool _discoveryWasRunning: false
|
||||
property bool _ctlInit: false
|
||||
property var _autoConnectQueue: []
|
||||
|
||||
// Persistent cache for per-device auto-connect toggle
|
||||
property string cacheFile: Settings.cacheDir + "bluetooth_devices.json"
|
||||
@@ -121,11 +122,27 @@ Singleton {
|
||||
|
||||
Timer {
|
||||
id: autoConnectTimer
|
||||
interval: 2000
|
||||
interval: 1500
|
||||
repeat: false
|
||||
onTriggered: root.attemptAutoConnect()
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: autoConnectStepTimer
|
||||
interval: 500
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
var device = root._autoConnectQueue.shift();
|
||||
if (device && device.paired && !device.connected && !device.blocked) {
|
||||
Logger.i("Bluetooth", "Auto-connecting to:", device.name || device.deviceName);
|
||||
connectDeviceWithTrust(device);
|
||||
}
|
||||
if (root._autoConnectQueue.length > 0) {
|
||||
autoConnectStepTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
Logger.i("Bluetooth", "Service started");
|
||||
}
|
||||
@@ -615,7 +632,7 @@ Singleton {
|
||||
const intervalMs = Math.max(500, Number(root.connectRetryIntervalMs) | 0);
|
||||
const intervalSec = Math.max(1, Math.round(intervalMs / 1000));
|
||||
|
||||
// Pause discovery during pair/connect to avoid interference
|
||||
// Temporarily pause discovery during pair/connect to reduce HCI churn
|
||||
root._discoveryWasRunning = root.scanningActive;
|
||||
if (root.scanningActive) {
|
||||
root.setScanActive(false);
|
||||
@@ -662,13 +679,10 @@ Singleton {
|
||||
return;
|
||||
}
|
||||
|
||||
var devList = adapter.devices.values.filter(function (dev) {
|
||||
return dev && dev.paired && !dev.connected && !dev.blocked && getDeviceAutoConnect(dev.address) === true;
|
||||
});
|
||||
_autoConnectQueue = adapter.devices.values.filter(dev => dev && dev.paired && !dev.connected && !dev.blocked && getDeviceAutoConnect(dev.address) === true);
|
||||
|
||||
for (var i = 0; i < devList.length; i++) {
|
||||
Logger.i("Bluetooth", "Auto-connecting to:", devList[i].name || devList[i].deviceName);
|
||||
connectDeviceWithTrust(devList[i]);
|
||||
if (root._autoConnectQueue.length > 0) {
|
||||
autoConnectStepTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user