From ae92c1c4eb07ea34feb9a962119d08c3fc1fb130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Fri, 30 Jul 2021 00:26:05 +0200 Subject: [PATCH] dbusServices/extensions: Split error page from window The error UI comprises the bits that are actually custom. Splitting them out from the off-the-shelf window makes it easier to replace the dialog with libadwaita's dedicated preference window. Part-of: --- .../extensions/extensionPrefsDialog.js | 102 +++++++------- .../extensions/ui/extension-error-page.ui | 122 ++++++++++++++++ .../extensions/ui/extension-prefs-dialog.ui | 131 ------------------ ...g.gnome.Shell.Extensions.src.gresource.xml | 2 +- 4 files changed, 176 insertions(+), 181 deletions(-) create mode 100644 js/dbusServices/extensions/ui/extension-error-page.ui delete mode 100644 js/dbusServices/extensions/ui/extension-prefs-dialog.ui diff --git a/js/dbusServices/extensions/extensionPrefsDialog.js b/js/dbusServices/extensions/extensionPrefsDialog.js index f9d533a8b..8fa6a533b 100644 --- a/js/dbusServices/extensions/extensionPrefsDialog.js +++ b/js/dbusServices/extensions/extensionPrefsDialog.js @@ -7,25 +7,53 @@ const ExtensionUtils = imports.misc.extensionUtils; var ExtensionPrefsDialog = GObject.registerClass({ GTypeName: 'ExtensionPrefsDialog', - Template: 'resource:///org/gnome/Shell/Extensions/ui/extension-prefs-dialog.ui', +}, class ExtensionPrefsDialog extends Gtk.Window { + _init(extension) { + super._init({ + title: extension.metadata.name, + default_width: 600, + default_height: 400, + }); + this.set_titlebar(new Gtk.HeaderBar()); + + try { + ExtensionUtils.installImporter(extension); + + // give extension prefs access to their own extension object + ExtensionUtils.getCurrentExtension = () => extension; + + const prefsModule = extension.imports.prefs; + prefsModule.init(extension.metadata); + + const widget = prefsModule.buildPrefsWidget(); + this.set_child(widget); + } catch (e) { + this.set_child(new ExtensionPrefsErrorPage(extension, e)); + logError(e, 'Failed to open preferences'); + } + } +}); + +const ExtensionPrefsErrorPage = GObject.registerClass({ + GTypeName: 'ExtensionPrefsErrorPage', + Template: 'resource:///org/gnome/Shell/Extensions/ui/extension-error-page.ui', InternalChildren: [ - 'stack', 'expander', 'expanderArrow', 'revealer', 'errorView', ], -}, class ExtensionPrefsDialog extends Gtk.Window { - _init(extension) { +}, class ExtensionPrefsErrorPage extends Gtk.Widget { + _init(extension, error) { super._init({ - title: extension.metadata.name, + layout_manager: new Gtk.BinLayout(), }); this._uuid = extension.uuid; this._url = extension.metadata.url || ''; this._actionGroup = new Gio.SimpleActionGroup(); - this.insert_action_group('win', this._actionGroup); + this.insert_action_group('page', this._actionGroup); this._initActions(); this._addCustomStylesheet(); @@ -50,22 +78,25 @@ var ExtensionPrefsDialog = GObject.registerClass({ this._revealer.connect('notify::child-revealed', () => this._syncExpandedStyle()); - try { - ExtensionUtils.installImporter(extension); + this._errorView.buffer.text = `${error}\n\nStack trace:\n`; + // Indent stack trace. + this._errorView.buffer.text += + error.stack.split('\n').map(line => ` ${line}`).join('\n'); - // give extension prefs access to their own extension object - ExtensionUtils.getCurrentExtension = () => extension; - - const prefsModule = extension.imports.prefs; - prefsModule.init(extension.metadata); - - const widget = prefsModule.buildPrefsWidget(); - this._stack.add_named(widget, 'prefs'); - this._stack.visible_child = widget; - } catch (e) { - this._setError(e); - logError(e, 'Failed to open preferences'); - } + // markdown for pasting in gitlab issues + let lines = [ + `The settings of extension ${this._uuid} had an error:`, + '```', + `${error}`, + '```', + '', + 'Stack trace:', + '```', + error.stack.replace(/\n$/, ''), // stack without trailing newline + '```', + '', + ]; + this._errorMarkdown = lines.join('\n'); } _syncExpandedStyle() { @@ -75,36 +106,10 @@ var ExtensionPrefsDialog = GObject.registerClass({ this._expander.remove_css_class('expanded'); } - _setError(exc) { - this._errorView.buffer.text = `${exc}\n\nStack trace:\n`; - // Indent stack trace. - this._errorView.buffer.text += - exc.stack.split('\n').map(line => ` ${line}`).join('\n'); - - // markdown for pasting in gitlab issues - let lines = [ - `The settings of extension ${this._uuid} had an error:`, - '```', - `${exc}`, - '```', - '', - 'Stack trace:', - '```', - exc.stack.replace(/\n$/, ''), // stack without trailing newline - '```', - '', - ]; - this._errorMarkdown = lines.join('\n'); - this._actionGroup.lookup('copy-error').enabled = true; - } - _initActions() { let action; - action = new Gio.SimpleAction({ - name: 'copy-error', - enabled: false, - }); + action = new Gio.SimpleAction({ name: 'copy-error' }); action.connect('activate', () => { const clipboard = this.get_display().get_clipboard(); clipboard.set(this._errorMarkdown); @@ -135,4 +140,3 @@ var ExtensionPrefsDialog = GObject.registerClass({ Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION); } }); - diff --git a/js/dbusServices/extensions/ui/extension-error-page.ui b/js/dbusServices/extensions/ui/extension-error-page.ui new file mode 100644 index 000000000..eb0a044cc --- /dev/null +++ b/js/dbusServices/extensions/ui/extension-error-page.ui @@ -0,0 +1,122 @@ + + + + diff --git a/js/dbusServices/extensions/ui/extension-prefs-dialog.ui b/js/dbusServices/extensions/ui/extension-prefs-dialog.ui deleted file mode 100644 index 28f9d1b2c..000000000 --- a/js/dbusServices/extensions/ui/extension-prefs-dialog.ui +++ /dev/null @@ -1,131 +0,0 @@ - - - - diff --git a/js/dbusServices/org.gnome.Shell.Extensions.src.gresource.xml b/js/dbusServices/org.gnome.Shell.Extensions.src.gresource.xml index bca8c75ec..c3b81cfc2 100644 --- a/js/dbusServices/org.gnome.Shell.Extensions.src.gresource.xml +++ b/js/dbusServices/org.gnome.Shell.Extensions.src.gresource.xml @@ -14,6 +14,6 @@ css/application.css - ui/extension-prefs-dialog.ui + ui/extension-error-page.ui