[gnome-shell-extensions] cleanup: Replace Promise wrappers



commit f6342d3b52e73c767b45938d1a0d2b0259ccbedb
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Feb 11 15:09:12 2022 +0100

    cleanup: Replace Promise wrappers
    
    gjs now supports overriding interface methods, which means that
    promisify started to work on interfaces.
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/214>

 extensions/drive-menu/extension.js     | 21 ++++++---------------
 extensions/places-menu/placeDisplay.js | 33 +++++----------------------------
 2 files changed, 11 insertions(+), 43 deletions(-)
---
diff --git a/extensions/drive-menu/extension.js b/extensions/drive-menu/extension.js
index cc31e77..5a70c44 100644
--- a/extensions/drive-menu/extension.js
+++ b/extensions/drive-menu/extension.js
@@ -10,6 +10,9 @@ const ShellMountOperation = imports.ui.shellMountOperation;
 
 const _ = ExtensionUtils.gettext;
 
+Gio._promisify(Gio.File.prototype,
+  'query_filesystem_info_async', 'query_filesystem_info_finish');
+
 var MountMenuItem = GObject.registerClass(
 class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
     _init(mount) {
@@ -55,20 +58,6 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
         super.destroy();
     }
 
-    _fsIsRemote(root) {
-        return new Promise((resolve, reject) => {
-            const attr = Gio.FILE_ATTRIBUTE_FILESYSTEM_REMOTE;
-            root.query_filesystem_info_async(attr, null, (o, res) => {
-                try {
-                    const info = root.query_filesystem_info_finish(res);
-                    resolve(!info.get_attribute_boolean(attr));
-                } catch (e) {
-                    reject(e);
-                }
-            });
-        });
-    }
-
     async _isInteresting() {
         if (!this.mount.can_eject() && !this.mount.can_unmount())
             return false;
@@ -83,7 +72,9 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
         const root = this.mount.get_root();
 
         try {
-            return await this._fsIsRemote(root);
+            const attr = Gio.FILE_ATTRIBUTE_FILESYSTEM_REMOTE;
+            const info = await root.query_filesystem_info_async(attr, null);
+            return !info.get_attribute_boolean(attr);
         } catch (e) {
             log(`Failed to query filesystem: ${e.message}`);
         }
diff --git a/extensions/places-menu/placeDisplay.js b/extensions/places-menu/placeDisplay.js
index 05b2280..a504c7b 100644
--- a/extensions/places-menu/placeDisplay.js
+++ b/extensions/places-menu/placeDisplay.js
@@ -10,6 +10,9 @@ const ShellMountOperation = imports.ui.shellMountOperation;
 const _ = ExtensionUtils.gettext;
 const N_ = x => x;
 
+Gio._promisify(Gio.AppInfo, 'launch_default_for_uri_async', 'launch_default_for_uri_finish');
+Gio._promisify(Gio.File.prototype, 'mount_enclosing_volume', 'mount_enclosing_volume_finish');
+
 const BACKGROUND_SCHEMA = 'org.gnome.desktop.background';
 
 const Hostname1Iface = '<node> \
@@ -40,7 +43,7 @@ class PlaceInfo {
 
     async _ensureMountAndLaunch(context, tryMount) {
         try {
-            await this._launchDefaultForUri(this.file.get_uri(), context, null);
+            await Gio.AppInfo.launch_default_for_uri_async(this.file.get_uri(), context, null);
         } catch (err) {
             if (!err.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_MOUNTED)) {
                 Main.notifyError(_('Failed to launch “%s”').format(this.name), err.message);
@@ -52,7 +55,7 @@ class PlaceInfo {
             };
             let op = new ShellMountOperation.ShellMountOperation(source);
             try {
-                await this._mountEnclosingVolume(0, op.mountOp, null);
+                await this.file.mount_enclosing_volume(0, op.mountOp, null);
 
                 if (tryMount)
                     this._ensureMountAndLaunch(context, false);
@@ -114,32 +117,6 @@ class PlaceInfo {
             throw e;
         }
     }
-
-    _launchDefaultForUri(uri, context, cancel) {
-        return new Promise((resolve, reject) => {
-            Gio.AppInfo.launch_default_for_uri_async(uri, context, cancel, (o, res) => {
-                try {
-                    Gio.AppInfo.launch_default_for_uri_finish(res);
-                    resolve();
-                } catch (e) {
-                    reject(e);
-                }
-            });
-        });
-    }
-
-    _mountEnclosingVolume(flags, mountOp, cancel) {
-        return new Promise((resolve, reject) => {
-            this.file.mount_enclosing_volume(flags, mountOp, cancel, (o, res) => {
-                try {
-                    this.file.mount_enclosing_volume_finish(res);
-                    resolve();
-                } catch (e) {
-                    reject(e);
-                }
-            });
-        });
-    }
 }
 Signals.addSignalMethods(PlaceInfo.prototype);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]