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>
This commit is contained in:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user