extensions: Add Extension/Preferences base classes
Extensions now must export a class that conforms to a particular interface both for the actual extension as well as for prefs: enable()/disable() methods for the former, fillPreferencesWindow() for the latter. This is quite similar to the previous method-based entry points, but it also gives us a more structured way of providing convenience API in form of base classes. Do that in form of Extension and ExtensionPreferences classes on top of a common ExtensionBase base class. getSettings(), initTranslations() and the gettext wrappers are now methods of the common base, while openPreferences() moves to the Extension class. Based on an original suggestion from Evan Welsh. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2838>
This commit is contained in:
@ -1,24 +1,21 @@
|
||||
import {getCurrentExtension, setExtensionManager} from './sharedInternals.js';
|
||||
import {ExtensionBase, setExtensionManager} from './sharedInternals.js';
|
||||
|
||||
export {
|
||||
getSettings,
|
||||
initTranslations,
|
||||
gettext,
|
||||
ngettext,
|
||||
pgettext
|
||||
} from './sharedInternals.js';
|
||||
export {gettext, ngettext, pgettext} from './sharedInternals.js';
|
||||
|
||||
const {extensionManager} = imports.ui.main;
|
||||
setExtensionManager(extensionManager);
|
||||
|
||||
/**
|
||||
* Open the preference dialog of the current extension
|
||||
*/
|
||||
export function openPrefs() {
|
||||
const extension = getCurrentExtension();
|
||||
export class Extension extends ExtensionBase {
|
||||
enable() {
|
||||
}
|
||||
|
||||
if (!extension)
|
||||
throw new Error('openPrefs() can only be called from extensions');
|
||||
disable() {
|
||||
}
|
||||
|
||||
extensionManager.openExtensionPrefs(extension.uuid, '', {});
|
||||
/**
|
||||
* Open the extension's preferences window
|
||||
*/
|
||||
openPreferences() {
|
||||
extensionManager.openExtensionPrefs(this.uuid, '', {});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user