From b50bdcbc54762326bd5c1fb646863a76a161921f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 17 Mar 2020 01:27:02 +0100 Subject: [PATCH] dbusMenu: Use GCancellable to stop pending async operations Fixes #212 --- dbusMenu.js | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/dbusMenu.js b/dbusMenu.js index 5ffd791..33b8802 100644 --- a/dbusMenu.js +++ b/dbusMenu.js @@ -206,7 +206,12 @@ const BusClientProxy = Gio.DBusProxy.makeProxyWrapper(DBusInterfaces.DBusMenu); var DBusClient = class AppIndicators_DBusClient { constructor(busName, busPath) { - this._proxy = new BusClientProxy(Gio.DBus.session, busName, busPath, this._clientReady.bind(this)) + this._cancellable = new Gio.Cancellable(); + this._proxy = new BusClientProxy(Gio.DBus.session, + busName, + busPath, + this._clientReady.bind(this), + this._cancellable) this._items = { 0: new DbusMenuItem(this, 0, { 'children-display': GLib.Variant.new_string('submenu') }, []) } // will be set to true if a layout update is requested while one is already in progress @@ -249,7 +254,10 @@ var DBusClient = class AppIndicators_DBusClient { } _beginRequestProperties() { - this._proxy.GetGroupPropertiesRemote(this._propertiesRequestedFor, [], this._endRequestProperties.bind(this)) + this._proxy.GetGroupPropertiesRemote(this._propertiesRequestedFor, + [], + this._cancellable, + this._endRequestProperties.bind(this)) this._propertiesRequestedFor = [] @@ -258,7 +266,8 @@ var DBusClient = class AppIndicators_DBusClient { _endRequestProperties(result, error) { if (error) { - Util.Logger.warn("Could not retrieve properties: "+error) + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + Util.Logger.warn(`Could not retrieve properties: ${error}`); return } @@ -294,7 +303,10 @@ var DBusClient = class AppIndicators_DBusClient { _beginLayoutUpdate() { // we only read the type property, because if the type changes after reading all properties, // the view would have to replace the item completely which we try to avoid - this._proxy.GetLayoutRemote(0, -1, [ 'type', 'children-display' ], this._endLayoutUpdate.bind(this)) + this._proxy.GetLayoutRemote(0, -1, + [ 'type', 'children-display' ], + this._cancellable, + this._endLayoutUpdate.bind(this)) this._flagLayoutUpdateRequired = false this._flagLayoutUpdateInProgress = true @@ -302,7 +314,8 @@ var DBusClient = class AppIndicators_DBusClient { _endLayoutUpdate(result, error) { if (error) { - Util.Logger.warn("While reading menu layout on proxy '"+this._proxy.g_name_owner+": "+error) + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + Util.Logger.warn(`While reading menu layout on proxy ${this._proxy.g_name_owner}: ${error}`); return } @@ -366,7 +379,8 @@ var DBusClient = class AppIndicators_DBusClient { _clientReady(result, error) { if (error) { - Util.Logger.warn("Could not initialize menu proxy: "+error) + if (!e.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.CANCELLED)) + Util.Logger.warn(`Could not initialize menu proxy: ${error}`); return; } @@ -411,7 +425,8 @@ var DBusClient = class AppIndicators_DBusClient { if (!this._proxy) return - this._proxy.EventRemote(id, event, params, timestamp, function(result, error) { /* we don't care */ }) + this._proxy.EventRemote(id, event, params, timestamp, this._cancellable, + () => { /* we don't care */ }) } _onLayoutUpdated() { @@ -439,6 +454,7 @@ var DBusClient = class AppIndicators_DBusClient { destroy() { this.emit('destroy') + this._cancellable.cancel(); Signals._disconnectAll.apply(this._proxy) this._proxy = null