[gnome-shell-extensions/wip/fmuellner/53-hide-network-mounts: 2/2] drive-menu: Avoid blocking I/O when querying filesystem




commit 519269be9d849551631b36564e3fb83ae5129099
Author: Florian Müllner <fmuellner gnome org>
Date:   Wed Jun 23 17:58:39 2021 +0200

    drive-menu: Avoid blocking I/O when querying filesystem
    
    The last commit improved the heuristics for detecting network mounts,
    but at the price of potentially blocking the shell. Avoid that drawback
    by making the code in question async.
    
    https://gitlab.gnome.org/GNOME/gnome-shell-extensions/issues/53
    
    Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell-extensions/-/merge_requests/27>

 extensions/drive-menu/extension.js | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
---
diff --git a/extensions/drive-menu/extension.js b/extensions/drive-menu/extension.js
index 59603c8..3fac236 100644
--- a/extensions/drive-menu/extension.js
+++ b/extensions/drive-menu/extension.js
@@ -54,7 +54,21 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
         super.destroy();
     }
 
-    _isInteresting() {
+    _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;
         if (this.mount.is_shadowed())
@@ -68,9 +82,7 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
         const root = this.mount.get_root();
 
         try {
-            const attr = Gio.FILE_ATTRIBUTE_FILESYSTEM_REMOTE;
-            const info = root.query_filesystem_info(attr, null);
-            return !info.get_attribute_boolean(attr);
+            return await this._fsIsRemote(root);
         } catch (e) {
             log(`Failed to query filesystem: ${e.message}`);
         }
@@ -79,8 +91,8 @@ class MountMenuItem extends PopupMenu.PopupBaseMenuItem {
         return Gio._LocalFilePrototype.isPrototypeOf(root);
     }
 
-    _syncVisibility() {
-        this.visible = this._isInteresting();
+    async _syncVisibility() {
+        this.visible = await this._isInteresting();
     }
 
     _eject() {


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