diff options
-rw-r--r-- | extension.js | 37 | ||||
-rw-r--r-- | metadata.json | 3 | ||||
-rw-r--r-- | quickSettings.js | 32 |
3 files changed, 64 insertions, 8 deletions
diff --git a/extension.js b/extension.js index b3c7167..fc90e89 100644 --- a/extension.js +++ b/extension.js @@ -31,11 +31,24 @@ const BatteryProvider = Me.imports.power.UPowerBatteryProvider; class BluetoothQuickConnect { - constructor(bluetooth, settings) { + constructor(quickSettings, bluetooth, settings) { this._logger = new Utils.Logger(settings); this._logger.info('Initializing extension'); - this._menu = bluetooth._item.menu; - this._proxy = bluetooth._proxy; + if (quickSettings) { + this._quickSettings = quickSettings; + this._btIndicator = quickSettings._bluetooth; + let oldItem = this._btIndicator.quickSettingsItems[0]; + let newItem = new Me.imports.quickSettings.BluetoothToggleMenu(oldItem); + this._btIndicator.quickSettingsItems = [newItem]; + quickSettings.menu.addItem(newItem); + quickSettings.menu._grid.set_child_below_sibling(newItem, oldItem); + quickSettings.menu._grid.remove_child(oldItem); + this._proxy = oldItem._client._proxy; + this._menu = newItem.menu; + } else { + this._menu = bluetooth._item.menu; + this._proxy = bluetooth._proxy; + } this._controller = new Bluetooth.BluetoothController(); this._settings = settings; this._battery_provider = new BatteryProvider(this._logger); @@ -218,10 +231,20 @@ let bluetoothQuickConnect = null; function init() {} function enable() { - bluetoothQuickConnect = new BluetoothQuickConnect( - Main.panel.statusArea.aggregateMenu._bluetooth, - new Settings() - ); + if (Main.panel.statusArea.quickSettings) { + bluetoothQuickConnect = new BluetoothQuickConnect( + Main.panel.statusArea.quickSettings, + null, + new Settings() + ); + } else { + bluetoothQuickConnect = new BluetoothQuickConnect( + null, + Main.panel.statusArea.aggregateMenu._bluetooth, + new Settings() + ); + } + bluetoothQuickConnect.test(); bluetoothQuickConnect.enable(); } diff --git a/metadata.json b/metadata.json index 924d940..7ccace1 100644 --- a/metadata.json +++ b/metadata.json @@ -8,6 +8,7 @@ "shell-version": [ "40", "41", - "42" + "42", + "43" ] } diff --git a/quickSettings.js b/quickSettings.js new file mode 100644 index 0000000..d521811 --- /dev/null +++ b/quickSettings.js @@ -0,0 +1,32 @@ +// Copyright 2010-2022 GNOME Shell contributors +// Copyright 2022 Simon McVittie +// SPDX-License-Identifier: GPL-2.0-or-later +// +// Adapted from gnome-shell js/ui/status/bluetooth.js + +/* exported BluetoothToggleMenu */ + +const {GObject} = imports.gi; +const {QuickMenuToggle} = imports.ui.quickSettings; + +var BluetoothToggleMenu = GObject.registerClass( +class BluetoothToggleMenu extends QuickMenuToggle { + _init(originalBluetoothToggle) { + super._init({label: originalBluetoothToggle.label}); + + this._original = originalBluetoothToggle; + this._client = this._original._client; + + this._original.bind_property('visible', this, 'visible', + GObject.BindingFlags.SYNC_CREATE); + this._original.bind_property('checked', this, 'checked', + GObject.BindingFlags.SYNC_CREATE); + this._original.bind_property('icon-name', this, 'icon-name', + GObject.BindingFlags.SYNC_CREATE); + + this.connect('clicked', () => this._client.toggleActive()); + + this.menu.setHeader('bluetooth-active-symbolic', originalBluetoothToggle.label); + } +}); + |