From 0c7446c1fc89979a00847ae7bbc0425600b92f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 8 Aug 2022 02:54:11 +0200 Subject: [PATCH 1/2] status/bluetooth: Fix call to undefined method The method started out as private and was then made public without updating the internal caller, whoops. Spotted by Sebastian Keller. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5722 Part-of: --- js/ui/status/bluetooth.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index aed017a477..580121a8da 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -42,7 +42,7 @@ const BtClient = GObject.registerClass({ const newAdapter = this._client.default_adapter ?? null; if (newAdapter && this._adapter) - this._setHadSetupDevices([...this._getDevices()].length > 0); + this._setHadSetupDevices([...this.getDevices()].length > 0); this._adapter = newAdapter; this._deviceNotifyConnected.clear(); -- GitLab From 4fd4b09919415046e6c56bf955dd3a61a2d0b928 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Mon, 8 Aug 2022 03:10:06 +0200 Subject: [PATCH 2/2] status/bluetooth: Fix remembering set up devices It is generally not possible to differentiate between systems without bluetooth support, and systems where a bluetooth adapter is powered down. We work around that by tracking whether there are any set up devices, and keep the bluetooth visible in that case, even when no adapter is present. However commit eeabdd150c7 moved updating the setting into the code that handles adapter changes, which is exactly the place where we carefully avoid changing the setting because it would be too unreliable (devices may have already disappeared, or not yet appeared). Fix this by changing _setHadSetupDevices() to _syncHadSetupDevices() and call that everywhere _sync() used to be called, *except* on adapter changes. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/5714 Part-of: --- js/ui/status/bluetooth.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index 580121a8da..f0a6923809 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -41,9 +41,6 @@ const BtClient = GObject.registerClass({ this._client.connect('notify::default-adapter', () => { const newAdapter = this._client.default_adapter ?? null; - if (newAdapter && this._adapter) - this._setHadSetupDevices([...this.getDevices()].length > 0); - this._adapter = newAdapter; this._deviceNotifyConnected.clear(); this.emit('devices-changed'); @@ -75,10 +72,12 @@ const BtClient = GObject.registerClass({ this._connectDeviceNotify(deviceStore.get_item(i)); this._client.connect('device-removed', (c, path) => { + this._syncHadSetupDevices(); this._deviceNotifyConnected.delete(path); this.emit('devices-changed'); }); this._client.connect('device-added', (c, device) => { + this._syncHadSetupDevices(); this._connectDeviceNotify(device); this.emit('devices-changed'); }); @@ -117,17 +116,25 @@ const BtClient = GObject.registerClass({ if (this._devicesChangedId) return; this._devicesChangedId = GLib.idle_add(GLib.PRIORITY_DEFAULT, () => { + this._syncHadSetupDevices(); delete this._devicesChangedId; this.emit('devices-changed'); return GLib.SOURCE_REMOVE; }); } - _setHadSetupDevices(value) { - if (this._hadSetupDevices === value) + _syncHadSetupDevices() { + const {defaultAdapter} = this._client; + if (!defaultAdapter || !this._adapter) + return; // ignore changes while powering up/down + + const [firstDevice] = this.getDevices(); + const hadSetupDevices = !!firstDevice; + + if (this._hadSetupDevices === hadSetupDevices) return; - this._hadSetupDevices = value; + this._hadSetupDevices = hadSetupDevices; global.settings.set_boolean( HAD_BLUETOOTH_DEVICES_SETUP, this._hadSetupDevices); } -- GitLab