From 7f7ae31fa38d03fb64e0c29717a88c6edf420096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 21 Nov 2023 13:28:30 +0100 Subject: [PATCH] dbusServices/extensions: Only show dialog when loaded After the port to ESM, an extension's `prefs.js` file is imported asynchronously. An unintended side effect of that is that we now show the dialog before anything can be added to the window (either by the extension, or the fallback error UI). The delay almost always won't be noticeable to users, but it's bad practice and prevents extensions from using some API that only works before the window is realized. To address the issue, add a `loaded` signal to the dialog that allows the caller to postpone showing the window until the UI is ready. Close: https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/7201 Part-of: --- js/dbusServices/extensions/extensionPrefsDialog.js | 5 ++++- js/dbusServices/extensions/extensionsService.js | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/js/dbusServices/extensions/extensionPrefsDialog.js b/js/dbusServices/extensions/extensionPrefsDialog.js index 6c1b5d508..50b2e92f5 100644 --- a/js/dbusServices/extensions/extensionPrefsDialog.js +++ b/js/dbusServices/extensions/extensionPrefsDialog.js @@ -9,6 +9,9 @@ import Gtk from 'gi://Gtk?version=4.0'; export const ExtensionPrefsDialog = GObject.registerClass({ GTypeName: 'ExtensionPrefsDialog', + Signals: { + 'loaded': {}, + }, }, class ExtensionPrefsDialog extends Adw.PreferencesWindow { _init(extension) { super._init({ @@ -21,7 +24,7 @@ export const ExtensionPrefsDialog = GObject.registerClass({ this._loadPrefs().catch(e => { this._showErrorPage(e); logError(e, 'Failed to open preferences'); - }); + }).finally(() => this.emit('loaded')); } async _loadPrefs() { diff --git a/js/dbusServices/extensions/extensionsService.js b/js/dbusServices/extensions/extensionsService.js index 0d60fb60e..f3f8f4156 100644 --- a/js/dbusServices/extensions/extensionsService.js +++ b/js/dbusServices/extensions/extensionsService.js @@ -137,6 +137,8 @@ export const ExtensionsService = class extends ServiceImplementation { const extension = extensionManager.createExtensionObject(serialized); this._prefsDialog = new ExtensionPrefsDialog(extension); + this._prefsDialog.connect('loaded', + () => this._prefsDialog.show()); this._prefsDialog.connect('realize', () => { let externalWindow = null; @@ -157,8 +159,6 @@ export const ExtensionsService = class extends ServiceImplementation { }); this.hold(); - this._prefsDialog.show(); - invocation.return_value(null); } catch (error) { this._handleError(invocation, error);