dbusServices/extensions: Load preferences as module
Now that extensions themselves are imported as modules, do the same for their preference dialogs. Extensions must now export a class with a `fillPreferencesWindow()` method as default. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2795>
This commit is contained in:
parent
e8ee845e41
commit
972a3b2d44
@ -18,29 +18,24 @@ export const ExtensionPrefsDialog = GObject.registerClass({
|
|||||||
search_enabled: false,
|
search_enabled: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
this._loadPrefs(extension).catch(e => {
|
||||||
ExtensionUtils.installImporter(extension);
|
this._showErrorPage(e);
|
||||||
|
logError(e, 'Failed to open preferences');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async _loadPrefs(extension) {
|
||||||
// give extension prefs access to their own extension object
|
// give extension prefs access to their own extension object
|
||||||
ExtensionUtils.setCurrentExtension(extension);
|
ExtensionUtils.setCurrentExtension(extension);
|
||||||
|
|
||||||
const prefsModule = extension.imports.prefs;
|
const prefsJs = extension.dir.get_child('prefs.js');
|
||||||
prefsModule.init(extension.metadata);
|
const prefsModule = await import(prefsJs.get_uri());
|
||||||
|
|
||||||
if (prefsModule.fillPreferencesWindow) {
|
const prefsObj = new prefsModule.default(extension.metadata);
|
||||||
prefsModule.fillPreferencesWindow(this);
|
prefsObj.fillPreferencesWindow(this);
|
||||||
|
|
||||||
if (!this.visible_page)
|
if (!this.visible_page)
|
||||||
throw new Error('Extension did not provide any UI');
|
throw new Error('Extension did not provide any UI');
|
||||||
} else {
|
|
||||||
const widget = prefsModule.buildPrefsWidget();
|
|
||||||
const page = this._wrapWidget(widget);
|
|
||||||
this.add(page);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
this._showErrorPage(e);
|
|
||||||
logError(e, 'Failed to open preferences');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set titlebar(w) {
|
set titlebar(w) {
|
||||||
@ -64,23 +59,6 @@ export const ExtensionPrefsDialog = GObject.registerClass({
|
|||||||
const extension = ExtensionUtils.getCurrentExtension();
|
const extension = ExtensionUtils.getCurrentExtension();
|
||||||
this.add(new ExtensionPrefsErrorPage(extension, e));
|
this.add(new ExtensionPrefsErrorPage(extension, e));
|
||||||
}
|
}
|
||||||
|
|
||||||
_wrapWidget(widget) {
|
|
||||||
if (widget instanceof Adw.PreferencesPage)
|
|
||||||
return widget;
|
|
||||||
|
|
||||||
const page = new Adw.PreferencesPage();
|
|
||||||
if (widget instanceof Adw.PreferencesGroup) {
|
|
||||||
page.add(widget);
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
const group = new Adw.PreferencesGroup();
|
|
||||||
group.add(widget);
|
|
||||||
page.add(group);
|
|
||||||
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const ExtensionPrefsErrorPage = GObject.registerClass({
|
const ExtensionPrefsErrorPage = GObject.registerClass({
|
||||||
|
Loading…
Reference in New Issue
Block a user