status/bluetooth: Show connected devices in subtitle

Now that quick toggles support subtitles, use it to indicate connected
devices.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2501>
This commit is contained in:
Florian Müllner 2023-02-08 14:31:10 +01:00 committed by Marge Bot
parent 384ab9f875
commit b7c3a7f6ed

View File

@ -164,7 +164,27 @@ class BluetoothToggle extends QuickToggle {
(bind, source) => [true, this._getIconNameFromState(source)], (bind, source) => [true, this._getIconNameFromState(source)],
null); null);
this._client.connectObject(
'devices-changed', () => this._sync(),
this);
this.connect('clicked', () => this._client.toggleActive()); this.connect('clicked', () => this._client.toggleActive());
this._sync();
}
_sync() {
const connectedDevices = [...this._client.getDevices()]
.filter(dev => dev.connected);
const nConnected = connectedDevices.length;
if (nConnected > 1)
/* Translators: This is the number of connected bluetooth devices */
this.subtitle = ngettext('%d Connected', '%d Connected', nConnected).format(nConnected);
else if (nConnected === 1)
this.subtitle = connectedDevices[0].alias;
else
this.subtitle = null;
} }
_getIconNameFromState(state) { _getIconNameFromState(state) {