status/bluetooth: Fix wedged state

Fix a state where toggling the main Bluetooth switch in the header will
always show the "Bluetooth Off" menu header with "Turn Off" as the only
option.

To reproduce, with Bluetooth enabled and working, run
"hciconfig hci0 down" as root, and check the status menu.

See gnome-bluetooth!102 and gnome-control-center!1148

Closes: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/4857
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2055>
This commit is contained in:
Bastien Nocera 2022-01-18 11:14:47 +01:00 committed by Marge Bot
parent 4a480a78af
commit 0531fc54e5

View File

@ -25,6 +25,7 @@ class Indicator extends PanelMenu.SystemIndicator {
this._indicator = this._addIndicator(); this._indicator = this._addIndicator();
this._indicator.icon_name = 'bluetooth-active-symbolic'; this._indicator.icon_name = 'bluetooth-active-symbolic';
this._hadSetupDevices = global.settings.get_boolean(HAD_BLUETOOTH_DEVICES_SETUP); this._hadSetupDevices = global.settings.get_boolean(HAD_BLUETOOTH_DEVICES_SETUP);
this._client = new GnomeBluetooth.Client();
this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH, this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
(proxy, error) => { (proxy, error) => {
@ -43,6 +44,8 @@ class Indicator extends PanelMenu.SystemIndicator {
this._toggleItem = new PopupMenu.PopupMenuItem(''); this._toggleItem = new PopupMenu.PopupMenuItem('');
this._toggleItem.connect('activate', () => { this._toggleItem.connect('activate', () => {
this._proxy.BluetoothAirplaneMode = !this._proxy.BluetoothAirplaneMode; this._proxy.BluetoothAirplaneMode = !this._proxy.BluetoothAirplaneMode;
if (!this._proxy.BluetoothAirplaneMode)
this._client.default_adapter_powered = true;
}); });
this._item.menu.addMenuItem(this._toggleItem); this._item.menu.addMenuItem(this._toggleItem);
@ -52,7 +55,6 @@ class Indicator extends PanelMenu.SystemIndicator {
this._syncId = 0; this._syncId = 0;
this._adapter = null; this._adapter = null;
this._client = new GnomeBluetooth.Client();
this._store = this._client.get_devices(); this._store = this._client.get_devices();
this._deviceNotifyConnected = []; this._deviceNotifyConnected = [];
this._client.connect('device-removed', (c, path) => { this._client.connect('device-removed', (c, path) => {
@ -146,6 +148,6 @@ class Indicator extends PanelMenu.SystemIndicator {
else else
this._item.label.text = _('Bluetooth On'); this._item.label.text = _('Bluetooth On');
this._toggleItem.label.text = this._proxy.BluetoothAirplaneMode ? _('Turn On') : _('Turn Off'); this._toggleItem.label.text = this._client.default_adapter_powered ? _('Turn Off') : _('Turn On');
} }
}); });