[gnome-shell] status/bluetooth: Use JS Set for tracking signal connections
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/bluetooth: Use JS Set for tracking signal connections
- Date: Fri, 18 Feb 2022 19:15:55 +0000 (UTC)
commit 34dcf2f7b13553fcf2e49ac42f95a7f0aec03a2b
Author: Jonas Dreßler <verdre v0yd nl>
Date: Thu Dec 2 11:44:47 2021 +0100
status/bluetooth: Use JS Set for tracking signal connections
We can make things a bit fancier here and use a JS Set instead of an
object for tracking which devices we're having a signal handler
connected to.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2188>
js/ui/status/bluetooth.js | 25 ++++++++++++++++---------
1 file changed, 16 insertions(+), 9 deletions(-)
---
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index d1304cac55..8738181223 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -55,10 +55,14 @@ class Indicator extends PanelMenu.SystemIndicator {
this._syncId = 0;
this._adapter = null;
- this._store = this._client.get_devices();
- this._deviceNotifyConnected = [];
+ this._deviceNotifyConnected = new Set();
+
+ const deviceStore = this._client.get_devices();
+ for (let i = 0; i < deviceStore.get_n_items(); i++)
+ this._connectDeviceNotify(deviceStore.get_item(i));
+
this._client.connect('device-removed', (c, path) => {
- this._deviceNotifyConnected[path] = false;
+ this._deviceNotifyConnected.delete(path);
this._queueSync.bind(this);
});
this._client.connect('device-added', (c, device) => {
@@ -79,21 +83,25 @@ class Indicator extends PanelMenu.SystemIndicator {
}
_connectDeviceNotify(device) {
- if (this._deviceNotifyConnected[device.get_object_path()] !== true)
+ const path = device.get_object_path();
+
+ if (this._deviceNotifyConnected.has(path))
return;
+
device.connect('notify::alias', this._queueSync.bind(this));
device.connect('notify::paired', this._queueSync.bind(this));
device.connect('notify::trusted', this._queueSync.bind(this));
device.connect('notify::connected', this._queueSync.bind(this));
- this._deviceNotifyConnected.push([device.get_object_path(), true]);
+
+ this._deviceNotifyConnected.add(path);
}
_getDeviceInfos() {
+ const deviceStore = this._client.get_devices();
let deviceInfos = [];
- const numDevices = this._store.get_n_items();
- for (let i = 0; i < numDevices; i++) {
- const device = this._store.get_item(i);
+ for (let i = 0; i < deviceStore.get_n_items(); i++) {
+ const device = deviceStore.get_item(i);
if (device.paired || device.trusted) {
deviceInfos.push({
@@ -101,7 +109,6 @@ class Indicator extends PanelMenu.SystemIndicator {
name: device.alias,
});
}
- this._connectDeviceNotify(device);
}
return deviceInfos;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]