[gnome-shell-extensions/gnome-40] drive-menu: Avoid blocking I/O when querying filesystem



commit 619de9d5ee0659884656ffc4dd8f507d002aa451
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>
    (cherry picked from commit 519269be9d849551631b36564e3fb83ae5129099)

 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]