Blame SOURCES/0001-desktop-icons-Don-t-use-blocking-IO.patch

66b32e
From 93e3e938b322433aff862bbc46f80c60ab7dc2ab Mon Sep 17 00:00:00 2001
66b32e
From: =?UTF-8?q?Florian=20M=C3=BCllner?= <fmuellner@gnome.org>
66b32e
Date: Tue, 17 Jan 2023 20:31:21 +0100
66b32e
Subject: [PATCH] desktop-icons: Don't use blocking IO
66b32e
66b32e
---
66b32e
 extensions/desktop-icons/desktopManager.js | 35 +++++++++++++++++-----
66b32e
 1 file changed, 28 insertions(+), 7 deletions(-)
66b32e
66b32e
diff --git a/extensions/desktop-icons/desktopManager.js b/extensions/desktop-icons/desktopManager.js
66b32e
index 399aee03..2ce6eefb 100644
66b32e
--- a/extensions/desktop-icons/desktopManager.js
66b32e
+++ b/extensions/desktop-icons/desktopManager.js
66b32e
@@ -53,6 +53,21 @@ function findMonitorIndexForPos(x, y) {
66b32e
     return getDpy().get_monitor_index_for_rect(new Meta.Rectangle({x, y}));
66b32e
 }
66b32e
 
66b32e
+async function queryInfo(file, attributes = DesktopIconsUtil.DEFAULT_ATTRIBUTES, cancellable = null) {
66b32e
+    const flags = Gio.FileQueryInfoFlags.NONE;
66b32e
+    const priority = GLib.PRIORITY_DEFAULT;
66b32e
+    return new Promise((resolve, reject) => {
66b32e
+        file.query_info_async(attributes, flags, priority, cancellable, (o, res) => {
66b32e
+            try {
66b32e
+                const info = file.query_info_finish(res);
66b32e
+                resolve(info);
66b32e
+            } catch (e) {
66b32e
+                reject(e);
66b32e
+            }
66b32e
+        });
66b32e
+    });
66b32e
+}
66b32e
+
66b32e
 
66b32e
 var DesktopManager = GObject.registerClass({
66b32e
     Properties: {
66b32e
@@ -221,9 +236,7 @@ var DesktopManager = GObject.registerClass({
66b32e
 
66b32e
         if (!this._unixMode) {
66b32e
             let desktopDir = DesktopIconsUtil.getDesktopDir();
66b32e
-            let fileInfo = desktopDir.query_info(Gio.FILE_ATTRIBUTE_UNIX_MODE,
66b32e
-                                                 Gio.FileQueryInfoFlags.NONE,
66b32e
-                                                 null);
66b32e
+            let fileInfo = await queryInfo(desktopDir, Gio.FILE_ATTRIBUTE_UNIX_MODE);
66b32e
             this._unixMode = fileInfo.get_attribute_uint32(Gio.FILE_ATTRIBUTE_UNIX_MODE);
66b32e
             this._setWritableByOthers((this._unixMode & S_IWOTH) != 0);
66b32e
         }
66b32e
@@ -268,14 +281,22 @@ var DesktopManager = GObject.registerClass({
66b32e
                 Gio.FileQueryInfoFlags.NONE,
66b32e
                 GLib.PRIORITY_DEFAULT,
66b32e
                 this._desktopEnumerateCancellable,
66b32e
-                (source, result) => {
66b32e
+                async (source, result) => {
66b32e
                     try {
66b32e
                         let fileEnum = source.enumerate_children_finish(result);
66b32e
+                        let extraFolders = await Promise.all(DesktopIconsUtil.getExtraFolders()
66b32e
+                            .map(async ([folder, extras]) => {
66b32e
+                                const info = await queryInfo(folder,
66b32e
+                                    DesktopIconsUtil.DEFAULT_ATTRIBUTES,
66b32e
+                                    this._desktopEnumerateCancellable);
66b32e
+                                return [folder, info, extras];
66b32e
+                            }));
66b32e
+
66b32e
                         let resultGenerator = function *() {
66b32e
+                            for (let [newFolder, info, extras] of extraFolders)
66b32e
+                                yield [newFolder, info, extras];
66b32e
+
66b32e
                             let info;
66b32e
-                            for (let [newFolder, extras] of DesktopIconsUtil.getExtraFolders()) {
66b32e
-                                yield [newFolder, newFolder.query_info(DesktopIconsUtil.DEFAULT_ATTRIBUTES, Gio.FileQueryInfoFlags.NONE, this._desktopEnumerateCancellable), extras];
66b32e
-                            }
66b32e
                             while ((info = fileEnum.next_file(null)))
66b32e
                                 yield [fileEnum.get_child(info), info, Prefs.FileType.NONE];
66b32e
                         }.bind(this);
66b32e
-- 
66b32e
2.38.1
66b32e