[gnome-shell] status/network: Override activate() for wireless



commit 791c65a5f943ac9e329ef67a9fcb1b11502f4946
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Aug 3 23:24:53 2022 +0200

    status/network: Override activate() for wireless
    
    Wireless items represent a single adapter, but wireless connectivity
    is controlled globally under NetworkManager.
    
    So instead of delegating activation to items, bind the :checked
    property to the global :wireless-enabled property and toggle it
    on activate.
    
    As any wireless devices will change their state to UNAVAILABLE
    when wireless is disabled, don't remove corresponding items in
    that case to keep the section visible.
    
    We don't want to hide the button to turn Wi-Fi back on when toggled
    off :-)
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2408>

 js/ui/status/network.js | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 431ca5ad68..28a5cfa0f9 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -1699,9 +1699,32 @@ class NMWirelessSection extends NMDeviceSection {
             'gnome-wifi-panel.desktop');
     }
 
+    setClient(client) {
+        super.setClient(client);
+
+        this._client?.bind_property('wireless-enabled',
+            this, 'checked',
+            GObject.BindingFlags.SYNC_CREATE);
+    }
+
+    activate() {
+        this._client.wireless_enabled = !this._client.wireless_enabled;
+    }
+
     _createDeviceMenuItem(device) {
         return new NMWirelessDeviceItem(this._client, device);
     }
+
+    _updateChecked() {
+        // handled via a property binding
+    }
+
+    _shouldShowDevice(device) {
+        // don't disappear if wireless-enabled is false
+        if (device.state === NM.DeviceState.UNAVAILABLE)
+            return true;
+        return super._shouldShowDevice(device);
+    }
 });
 
 const NMWiredSection = GObject.registerClass(


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]