From 26c2cb9f65cfca25c3affc38dbbad46593b5de19 Mon Sep 17 00:00:00 2001 From: Mariana Picolo Date: Mon, 30 Mar 2020 05:48:06 -0300 Subject: [PATCH 1/2] bluetooth: Add getDeviceInfos function In case where only one device is connected, we want to display its name in the menu. For that we will need more than the number of known/connected devices, so change the function to return an array of device infos instead. https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2340 --- js/ui/status/bluetooth.js | 52 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index 957669dbb0..8ba98ab491 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -72,46 +72,44 @@ class Indicator extends PanelMenu.SystemIndicator { return null; } - // nDevices is the number of devices setup for the current default - // adapter if one exists and is powered. If unpowered or unavailable, - // nDevice is "1" if it had setup devices associated to it the last - // time it was seen, and "-1" if not. - // - // nConnectedDevices is the number of devices connected to the default - // adapter if one exists and is powered, or -1 if it's not available. - _getNDevices() { - let adapter = this._getDefaultAdapter(); + _getDeviceInfos(adapter) { if (!adapter) - return [this._hadSetupDevices ? 1 : -1, -1]; + return []; - let nConnectedDevices = 0; - let nDevices = 0; + let deviceInfos = []; let [ret, iter] = this._model.iter_children(adapter); while (ret) { - let isConnected = this._model.get_value(iter, - GnomeBluetooth.Column.CONNECTED); - if (isConnected) - nConnectedDevices++; - - let isPaired = this._model.get_value(iter, - GnomeBluetooth.Column.PAIRED); - let isTrusted = this._model.get_value(iter, - GnomeBluetooth.Column.TRUSTED); - if (isPaired || isTrusted) - nDevices++; + const isPaired = this._model.get_value(iter, + GnomeBluetooth.Column.PAIRED); + const isTrusted = this._model.get_value(iter, + GnomeBluetooth.Column.TRUSTED); + + if (!isPaired && !isTrusted) + continue; + + deviceInfos.push({ + connected: this._model.get_value(iter, + GnomeBluetooth.Column.CONNECTED), + }); + ret = this._model.iter_next(iter); } - if (this._hadSetupDevices != (nDevices > 0)) { + if (this._hadSetupDevices !== (deviceInfos.length > 0)) { this._hadSetupDevices = !this._hadSetupDevices; global.settings.set_boolean(HAD_BLUETOOTH_DEVICES_SETUP, this._hadSetupDevices); } - return [nDevices, nConnectedDevices]; + return deviceInfos; } _sync() { - let [nDevices, nConnectedDevices] = this._getNDevices(); + let adapter = this._getDefaultAdapter(); + let devices = this._getDeviceInfos(adapter); + const connectedDevices = devices.filter(dev => dev.connected); + const nConnectedDevices = connectedDevices.length; + const nDevices = devices.length; + let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter; this.menu.setSensitive(sensitive); @@ -127,7 +125,7 @@ class Indicator extends PanelMenu.SystemIndicator { if (nConnectedDevices > 0) /* Translators: this is the number of connected bluetooth devices */ this._item.label.text = ngettext("%d Connected", "%d Connected", nConnectedDevices).format(nConnectedDevices); - else if (nConnectedDevices == -1) + else if (adapter === null) this._item.label.text = _("Off"); else this._item.label.text = _("On"); -- GitLab From 9bc9d5165fe6a9453c6d1a4cbb6a1c567c68de4d Mon Sep 17 00:00:00 2001 From: Mariana Picolo Date: Sat, 28 Mar 2020 15:56:20 -0300 Subject: [PATCH 2/2] bluetooth: Update bluetooth submenu title - "Bluetooth" to "on/off" labels to match with other menus - Display single connected device name to show more relevant information https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/2340 --- js/ui/status/bluetooth.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index 8ba98ab491..ab167be028 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -90,6 +90,8 @@ class Indicator extends PanelMenu.SystemIndicator { deviceInfos.push({ connected: this._model.get_value(iter, GnomeBluetooth.Column.CONNECTED), + name: this._model.get_value(iter, + GnomeBluetooth.Column.ALIAS), }); ret = this._model.iter_next(iter); @@ -122,14 +124,16 @@ class Indicator extends PanelMenu.SystemIndicator { else this._item.visible = this._proxy.BluetoothHasAirplaneMode && !this._proxy.BluetoothAirplaneMode; - if (nConnectedDevices > 0) + if (nConnectedDevices > 1) /* Translators: this is the number of connected bluetooth devices */ - this._item.label.text = ngettext("%d Connected", "%d Connected", nConnectedDevices).format(nConnectedDevices); + this._item.label.text = ngettext('%d Connected", "%d Connected', nConnectedDevices).format(nConnectedDevices); + else if (nConnectedDevices === 1) + this._item.label.text = connectedDevices[0].name; else if (adapter === null) - this._item.label.text = _("Off"); + this._item.label.text = _('Bluetooth Off'); else - this._item.label.text = _("On"); + this._item.label.text = _('Bluetooth On'); - this._toggleItem.label.text = this._proxy.BluetoothAirplaneMode ? _("Turn On") : _("Turn Off"); + this._toggleItem.label.text = this._proxy.BluetoothAirplaneMode ? _('Turn On') : _('Turn Off'); } }); -- GitLab