From b7c3a7f6eda9082375b81268b72b71e8a10ecea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 8 Feb 2023 14:31:10 +0100 Subject: [PATCH] status/bluetooth: Show connected devices in subtitle Now that quick toggles support subtitles, use it to indicate connected devices. Part-of: --- js/ui/status/bluetooth.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js index 4b828bd1e..2851f2d27 100644 --- a/js/ui/status/bluetooth.js +++ b/js/ui/status/bluetooth.js @@ -164,7 +164,27 @@ class BluetoothToggle extends QuickToggle { (bind, source) => [true, this._getIconNameFromState(source)], null); + this._client.connectObject( + 'devices-changed', () => this._sync(), + this); + 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) {