[gnome-shell] status/bluetooth: Use promise to initialize proxy
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-shell] status/bluetooth: Use promise to initialize proxy
- Date: Mon, 1 Aug 2022 12:38:12 +0000 (UTC)
commit 463757569a9c235d6dd19492f533cd8cbc89b6ed
Author: Florian Müllner <fmuellner gnome org>
Date: Fri Jul 29 12:57:50 2022 +0200
status/bluetooth: 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 allows us to rely on the signal parameters to only process
changed properties.
To achieve that, construct the proxy manually, and then initialize
it asynchronously in a Promise.
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2391>
js/ui/status/bluetooth.js | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
---
diff --git a/js/ui/status/bluetooth.js b/js/ui/status/bluetooth.js
index 5e985dd1af..93dde6a763 100644
--- a/js/ui/status/bluetooth.js
+++ b/js/ui/status/bluetooth.js
@@ -13,7 +13,7 @@ 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);
const HAD_BLUETOOTH_DEVICES_SETUP = 'had-bluetooth-devices-setup';
@@ -40,16 +40,19 @@ class Indicator extends PanelMenu.SystemIndicator {
});
this._client.connect('notify::default-adapter-powered', this._sync.bind(this));
- this._proxy = new RfkillManagerProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
- (proxy, error) => {
- if (error) {
- log(error.message);
- return;
- }
-
- this._sync();
- });
- this._proxy.connect('g-properties-changed', this._queueSync.bind(this));
+ 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', (p, properties) => {
+ if ('BluetoothHardwareAirplaneMode' in properties.unpack())
+ this._sync();
+ });
+ this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
+ .catch(e => console.error(e.message));
this._item = new PopupMenu.PopupSubMenuMenuItem(_("Bluetooth"), true);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]