extension-tool: Use Extension base class in templates

The Extension/Preferences classes are where we will focus for
future extension convenience API, so developers should be
encouraged to use them as entry points.

Adjust the existing templates to do that.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2838>
This commit is contained in:
Florian Müllner 2023-07-10 11:50:15 +02:00
parent 3e4fd4b67a
commit 348a8e49fe
2 changed files with 6 additions and 17 deletions

View File

@ -16,18 +16,15 @@
* SPDX-License-Identifier: GPL-2.0-or-later * SPDX-License-Identifier: GPL-2.0-or-later
*/ */
const GETTEXT_DOMAIN = 'my-indicator-extension';
import GObject from 'gi://GObject'; import GObject from 'gi://GObject';
import St from 'gi://St'; import St from 'gi://St';
const ExtensionUtils = imports.misc.extensionUtils; import {Extension, gettext as _} from 'resource:///org/gnome/shell/extensions/extension.js';
const Main = imports.ui.main; const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu; const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu; const PopupMenu = imports.ui.popupMenu;
const _ = ExtensionUtils.gettext;
const Indicator = GObject.registerClass( const Indicator = GObject.registerClass(
class Indicator extends PanelMenu.Button { class Indicator extends PanelMenu.Button {
_init() { _init() {
@ -46,16 +43,10 @@ class Indicator extends PanelMenu.Button {
} }
}); });
export default class Extension { export default class IndicatorExampleExtension extends Extension {
constructor(metadata) {
this._uuid = metadata.uuid;
ExtensionUtils.initTranslations(GETTEXT_DOMAIN);
}
enable() { enable() {
this._indicator = new Indicator(); this._indicator = new Indicator();
Main.panel.addToStatusArea(this._uuid, this._indicator); Main.panel.addToStatusArea(this.uuid, this._indicator);
} }
disable() { disable() {

View File

@ -15,11 +15,9 @@
* *
* SPDX-License-Identifier: GPL-2.0-or-later * SPDX-License-Identifier: GPL-2.0-or-later
*/ */
import {Extension} from 'resource:///org/gnome/shell/extensions/extension.js';
export default class Extension { export default class PlainExampleExtension extends Extension {
constructor() {
}
enable() { enable() {
} }