From 93fa1034f51594fa4e61d2f8bde8ecdae39ddbdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Thu, 19 Dec 2019 03:28:50 +0100 Subject: [PATCH] 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 --- js/ui/grabHelper.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/ui/grabHelper.js b/js/ui/grabHelper.js index ffe07b2ec..2ba2aad9a 100644 --- a/js/ui/grabHelper.js +++ b/js/ui/grabHelper.js @@ -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) {