From 619de9d5ee0659884656ffc4dd8f507d002aa451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Wed, 23 Jun 2021 17:58:39 +0200 Subject: [PATCH] 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: (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 59603c80..3fac2360 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() {