From 62c79476579bdfae91d4d3a584d7328f2c17c756 Mon Sep 17 00:00:00 2001 From: Turann_ Date: Thu, 5 Mar 2026 23:01:23 +0300 Subject: [PATCH] Update BluetoothService.qml --- Services/Networking/BluetoothService.qml | 48 ++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/Services/Networking/BluetoothService.qml b/Services/Networking/BluetoothService.qml index 22b41495c..7d9021111 100644 --- a/Services/Networking/BluetoothService.qml +++ b/Services/Networking/BluetoothService.qml @@ -68,6 +68,46 @@ Singleton { property bool _discoveryWasRunning: false property bool _ctlInit: false + // Persistent cache for per-device auto-connect toggle + property string cacheFile: Settings.cacheDir + "bluetooth_devices.json" + + FileView { + id: cacheFileView + path: root.cacheFile + printErrors: false + + JsonAdapter { + id: cacheAdapter + property var autoConnectSettings: ({}) + } + } + + function getDeviceAutoConnect(mac) { + if (!mac || !cacheAdapter.autoConnectSettings) { + return false; + } + const settings = cacheAdapter.autoConnectSettings[mac]; + return settings ? !!settings.autoConnect : false; + } + + function setDeviceAutoConnect(device, enabled) { + if (!device || !device.address) { + return; + } + const mac = device.address; + let settings = cacheAdapter.autoConnectSettings || ({}); + if (enabled) { + settings[mac] = { + autoConnect: true, + deviceName: device.name || device.deviceName || "" + }; + } else { + delete settings[mac]; + } + cacheAdapter.autoConnectSettings = settings; + cacheFileView.writeAdapter(); + } + Connections { target: Settings.data.network function onBluetoothAutoConnectChanged() { @@ -621,12 +661,14 @@ Singleton { } var devList = adapter.devices.values.filter(function (dev) { - return dev && dev.paired && !dev.connected && !dev.blocked; + return 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]); + let dev = devList[i]; + Logger.i("Bluetooth", "Auto-connecting to:", dev.name || dev.deviceName); + + connectDeviceWithTrust(dev); } }