[gnome-shell] rfkill: Turn manager into a GObject



commit 98cbc31e860b38aeeff1e2f4544c94314d4223c8
Author: Florian Müllner <fmuellner gnome org>
Date:   Mon Jul 18 20:28:13 2022 +0200

    rfkill: Turn manager into a GObject
    
    That will allow us to use it in property bindings.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2385>

 js/ui/status/network.js |  6 ++++--
 js/ui/status/rfkill.js  | 54 ++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 44 insertions(+), 16 deletions(-)
---
diff --git a/js/ui/status/network.js b/js/ui/status/network.js
index 1598941b63..bc6cbb7eb5 100644
--- a/js/ui/status/network.js
+++ b/js/ui/status/network.js
@@ -750,8 +750,10 @@ class NMWirelessDialog extends ModalDialog.ModalDialog {
             this._syncView.bind(this), this);
 
         this._rfkill = Rfkill.getRfkillManager();
-        this._rfkill.connectObject('airplane-mode-changed',
-            this._syncView.bind(this), this);
+        this._rfkill.connectObject(
+            'notify::airplane-mode', () => this._syncView(),
+            'notify::hw-airplane-mode', () => this._syncView(),
+            this);
 
         this._networks = [];
         this._buildLayout();
diff --git a/js/ui/status/rfkill.js b/js/ui/status/rfkill.js
index e29de295a6..332d1643f4 100644
--- a/js/ui/status/rfkill.js
+++ b/js/ui/status/rfkill.js
@@ -2,7 +2,6 @@
 /* exported Indicator */
 
 const {Gio, GLib, GObject} = imports.gi;
-const Signals = imports.misc.signals;
 
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
@@ -16,7 +15,22 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
 const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
 const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
 
-var RfkillManager = class extends Signals.EventEmitter {
+const RfkillManager = GObject.registerClass({
+    Properties: {
+        'airplane-mode': GObject.ParamSpec.boolean(
+            'airplane-mode', '', '',
+            GObject.ParamFlags.READWRITE,
+            false),
+        'hw-airplane-mode': GObject.ParamSpec.boolean(
+            'hw-airplane-mode', '', '',
+            GObject.ParamFlags.READABLE,
+            false),
+        'show-airplane-mode': GObject.ParamSpec.boolean(
+            'show-airplane-mode', '', '',
+            GObject.ParamFlags.READABLE,
+            false),
+    },
+}, class RfkillManager extends GObject.Object {
     constructor() {
         super();
 
@@ -32,26 +46,40 @@ var RfkillManager = class extends Signals.EventEmitter {
             .catch(e => console.error(e.message));
     }
 
-    get airplaneMode() {
+    /* eslint-disable camelcase */
+    get airplane_mode() {
         return this._proxy.AirplaneMode;
     }
 
-    set airplaneMode(v) {
+    set airplane_mode(v) {
         this._proxy.AirplaneMode = v;
     }
 
-    get hwAirplaneMode() {
+    get hw_airplane_mode() {
         return this._proxy.HardwareAirplaneMode;
     }
 
-    get shouldShowAirplaneMode() {
+    get show_airplane_mode() {
         return this._proxy.ShouldShowAirplaneMode;
     }
-
-    _changed() {
-        this.emit('airplane-mode-changed');
+    /* eslint-enable camelcase */
+
+    _changed(proxy, properties) {
+        for (const prop in properties.deep_unpack()) {
+            switch (prop) {
+            case 'AirplaneMode':
+                this.notify('airplane-mode');
+                break;
+            case 'HardwareAirplaneMode':
+                this.notify('hw-airplane-mode');
+                break;
+            case 'ShouldShowAirplaneMode':
+                this.notify('show-airplane-mode');
+                break;
+            }
+        }
     }
-};
+});
 
 var _manager;
 function getRfkillManager() {
@@ -68,7 +96,7 @@ class Indicator extends PanelMenu.SystemIndicator {
         super._init();
 
         this._manager = getRfkillManager();
-        this._manager.connect('airplane-mode-changed', this._sync.bind(this));
+        this._manager.connect('notify', () => this._sync());
 
         this._indicator = this._addIndicator();
         this._indicator.icon_name = 'airplane-mode-symbolic';
@@ -97,9 +125,7 @@ class Indicator extends PanelMenu.SystemIndicator {
     }
 
     _sync() {
-        let airplaneMode = this._manager.airplaneMode;
-        let hwAirplaneMode = this._manager.hwAirplaneMode;
-        let showAirplaneMode = this._manager.shouldShowAirplaneMode;
+        const {airplaneMode, hwAirplaneMode, showAirplaneMode} = this._manager;
 
         this._indicator.visible = airplaneMode && showAirplaneMode;
         this._item.visible = airplaneMode && showAirplaneMode;


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