Skip to content

Commit

Permalink
locations: Keep track of launch wait timeouts
Browse files Browse the repository at this point in the history
Ensure we drop the timeouts on we have to launch the default locations
handlers.
  • Loading branch information
3v1n0 committed Feb 27, 2023
1 parent 2539020 commit 61cc0be
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,35 @@ var LocationAppInfo = GObject.registerClass({
// workaround this by using the async API in a sync way, but we need to
// use a timeout to avoid this to hang forever, better than hang the
// shell.
let handler, error;
let handler, error, launchMaxWaitId;
Promise.race([
this._getHandlerAppAsync(cancellable),
new Promise((resolve, reject) =>
GLib.timeout_add(GLib.PRIORITY_DEFAULT, LAUNCH_HANDLER_MAX_WAIT, () => {
cancellable.cancel();
reject(new GLib.Error(Gio.IOErrorEnum,
Gio.IOErrorEnum.TIMED_OUT,
`Searching for ${this.get_id()} handler took too long`));
return GLib.SOURCE_REMOVE;
})
(launchMaxWaitId = GLib.timeout_add(GLib.PRIORITY_DEFAULT,
LAUNCH_HANDLER_MAX_WAIT, () => {
launchMaxWaitId = 0;
cancellable.cancel();
reject(new GLib.Error(Gio.IOErrorEnum,
Gio.IOErrorEnum.TIMED_OUT,
`Searching for ${this.get_id()} handler took too long`));
return GLib.SOURCE_REMOVE;
}))
),
]).then(h => (handler = h)).catch(e => (error = e));

if (this._launchMaxWaitIds === undefined)
this._launchMaxWaitIds = new Set();

this._launchMaxWaitIds.add(launchMaxWaitId);

while (handler === undefined && error === undefined)
GLib.MainContext.default().iteration(false);

if (launchMaxWaitId) {
GLib.source_remove(launchMaxWaitId);
this._launchMaxWaitIds.delete(launchMaxWaitId);
}

if (this._handlerApp && error?.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.TIMED_OUT))
return this._handlerApp;

Expand All @@ -382,6 +394,8 @@ var LocationAppInfo = GObject.registerClass({
}

destroy() {
this._launchMaxWaitIds.forEach(id => GLib.source_remove(id));
this._launchMaxWaitIds = null;
this.location = null;
this.icon = null;
this.name = null;
Expand Down

0 comments on commit 61cc0be

Please sign in to comment.