Skip to content

Commit

Permalink
dbusMenu: Use GCancellable to stop pending async operations
Browse files Browse the repository at this point in the history
Fixes #212
  • Loading branch information
3v1n0 committed Mar 17, 2020
1 parent c2bf83e commit b50bdcb
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions dbusMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []

Expand All @@ -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
}

Expand Down Expand Up @@ -294,15 +303,19 @@ 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
}

_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
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -439,6 +454,7 @@ var DBusClient = class AppIndicators_DBusClient {
destroy() {
this.emit('destroy')

this._cancellable.cancel();
Signals._disconnectAll.apply(this._proxy)

this._proxy = null
Expand Down

0 comments on commit b50bdcb

Please sign in to comment.