grabHelper: Add (promised-based) grabAsync()

Some GrabHelper uses are in the form:

    doPreGrabStuff();

    this._grabHelper.grab({
        onUngrab: () => {
            undoPreGrabStuff();
        },
    });

A promise-based variant allows to write this more cleanly as:

    doPreGrabStuff();

    await this._grabHelper.grabAsync();

    undoPreGrabStuff();

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/903
This commit is contained in:
Florian Müllner 2019-12-19 03:28:50 +01:00
parent 35494f5d08
commit 93fa1034f5

View File

@ -194,6 +194,15 @@ var GrabHelper = class GrabHelper {
return true;
}
grabAsync(params) {
return new Promise((resolve, reject) => {
params.onUngrab = resolve;
if (!this.grab(params))
reject(new Error('Grab failed'));
});
}
_takeModalGrab() {
let firstGrab = this._modalCount == 0;
if (firstGrab) {