[gnome-shell] rfkill: Use promise to initialize proxy



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

    rfkill: Use promise to initialize proxy
    
    There's no good reason for waiting for the proxy to be initialized
    to connect signals. In fact, connecting the signal beforehand
    ensures that the handler is in place when the proxy fetches the
    properties, so we don't have to call the handler explicitly.
    
    That in turn will allow us in a follow-up to rely on the signal
    parameters to only process changed properties.
    
    To achieve that by constructing the proxy manually, and then
    initialize it asynchronously in a Promise.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2385>

 js/ui/status/rfkill.js | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)
---
diff --git a/js/ui/status/rfkill.js b/js/ui/status/rfkill.js
index 518da25615..e29de295a6 100644
--- a/js/ui/status/rfkill.js
+++ b/js/ui/status/rfkill.js
@@ -1,35 +1,35 @@
 // -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
 /* exported Indicator */
 
-const { Gio, GObject } = imports.gi;
+const {Gio, GLib, GObject} = imports.gi;
 const Signals = imports.misc.signals;
 
 const Main = imports.ui.main;
 const PanelMenu = imports.ui.panelMenu;
 const PopupMenu = imports.ui.popupMenu;
 
-const { loadInterfaceXML } = imports.misc.fileUtils;
+const {loadInterfaceXML} = imports.misc.fileUtils;
 
 const BUS_NAME = 'org.gnome.SettingsDaemon.Rfkill';
 const OBJECT_PATH = '/org/gnome/SettingsDaemon/Rfkill';
 
 const RfkillManagerInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Rfkill');
-const RfkillManagerProxy = Gio.DBusProxy.makeProxyWrapper(RfkillManagerInterface);
+const rfkillManagerInfo = Gio.DBusInterfaceInfo.new_for_xml(RfkillManagerInterface);
 
 var RfkillManager = class extends Signals.EventEmitter {
     constructor() {
         super();
 
-        this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
-            (proxy, error) => {
-                if (error) {
-                    log(error.message);
-                    return;
-                }
-                this._proxy.connect('g-properties-changed',
-                    this._changed.bind(this));
-                this._changed();
-            });
+        this._proxy = new Gio.DBusProxy({
+            g_connection: Gio.DBus.session,
+            g_name: BUS_NAME,
+            g_object_path: OBJECT_PATH,
+            g_interface_name: rfkillManagerInfo.name,
+            g_interface_info: rfkillManagerInfo,
+        });
+        this._proxy.connect('g-properties-changed', this._changed.bind(this));
+        this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
+            .catch(e => console.error(e.message));
     }
 
     get airplaneMode() {


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