Refactor Bluetooth scanning logic to use persistent fallback process, improve error handling, and update translations for consistency.

This commit is contained in:
danny
2026-01-04 21:19:38 +01:00
parent 1d7f621289
commit de4600a803
6 changed files with 24 additions and 15 deletions
+2 -1
View File
@@ -90,7 +90,8 @@ Item {
forceClose: isBarVertical || root.displayMode === "alwaysHide" || text === ""
onClicked: {
var p = PanelService.getPanel("bluetoothPanel", screen);
if (p) p.toggle(this);
if (p)
p.toggle(this);
}
onRightClicked: {
var popupMenuWindow = PanelService.getPopupMenuWindow(screen);
@@ -134,10 +134,14 @@ NBox {
NText {
text: {
const k = BluetoothService.getStatusKey(modelData);
if (k === "pairing") return I18n.tr("bluetooth.panel.pairing");
if (k === "blocked") return I18n.tr("bluetooth.panel.blocked");
if (k === "connecting") return I18n.tr("bluetooth.panel.connecting");
if (k === "disconnecting") return I18n.tr("bluetooth.panel.disconnecting");
if (k === "pairing")
return I18n.tr("bluetooth.panel.pairing");
if (k === "blocked")
return I18n.tr("bluetooth.panel.blocked");
if (k === "connecting")
return I18n.tr("bluetooth.panel.connecting");
if (k === "disconnecting")
return I18n.tr("bluetooth.panel.disconnecting");
return "";
}
visible: text !== ""
+4 -4
View File
@@ -272,8 +272,8 @@ SmartPanel {
return false;
var availableCount = BluetoothService.adapter.devices.values.filter(dev => {
return dev && !dev.blocked && (dev.signalStrength === undefined || dev.signalStrength > 0);
}).length;
return dev && !dev.blocked && (dev.signalStrength === undefined || dev.signalStrength > 0);
}).length;
return (availableCount === 0);
}
Layout.fillWidth: true
@@ -326,8 +326,8 @@ SmartPanel {
}
var availableCount = BluetoothService.adapter.devices.values.filter(dev => {
return dev && !dev.paired && !dev.pairing && !dev.blocked && (dev.signalStrength === undefined || dev.signalStrength > 0);
}).length;
return dev && !dev.paired && !dev.pairing && !dev.blocked && (dev.signalStrength === undefined || dev.signalStrength > 0);
}).length;
return (availableCount === 0);
}
@@ -12,7 +12,8 @@ NIconButtonHot {
tooltipText: I18n.tr("quickSettings.bluetooth.tooltip.action")
onClicked: {
var p = PanelService.getPanel("bluetoothPanel", screen);
if (p) p.toggle(this);
if (p)
p.toggle(this);
}
onRightClicked: BluetoothService.setBluetoothEnabled(!BluetoothService.enabled)
}
+1 -1
View File
@@ -41,7 +41,7 @@ ColumnLayout {
description: I18n.tr("settings.network.bluetooth.rssi-polling.description")
checked: Settings.data && Settings.data.network && Settings.data.network.bluetoothRssiPollingEnabled
enabled: BluetoothService.enabled
onToggled: function(checked) {
onToggled: function (checked) {
if (Settings.data && Settings.data.network) {
Settings.data.network.bluetoothRssiPollingEnabled = checked;
}
+7 -4
View File
@@ -23,7 +23,9 @@ QtObject {
property Process rssiProcess: Process {
id: proc
running: false
stdout: StdioCollector { id: out }
stdout: StdioCollector {
id: out
}
onExited: function (exitCode, exitStatus) {
try {
var text = out.text || "";
@@ -35,8 +37,7 @@ QtObject {
root.version++;
}
}
} catch (e) {
} finally {
} catch (e) {} finally {
root._currentAddr = "";
}
}
@@ -63,7 +64,9 @@ QtObject {
return; // avoid overlap
root._currentAddr = addr;
proc.command = ["sh", "-c", `bluetoothctl info "${addr}"`];
try { proc.running = true; } catch (e) {}
try {
proc.running = true;
} catch (e) {}
}
}
}