From 3396b8d445e567359367a3190a821f1b72cc08cd Mon Sep 17 00:00:00 2001 From: Pascal Garber Date: Wed, 27 Mar 2024 21:56:16 +0100 Subject: [PATCH] Update example --- examples/hello-world/src/extension.ts | 46 +++++++-------------------- 1 file changed, 12 insertions(+), 34 deletions(-) diff --git a/examples/hello-world/src/extension.ts b/examples/hello-world/src/extension.ts index ca034b2..c655731 100644 --- a/examples/hello-world/src/extension.ts +++ b/examples/hello-world/src/extension.ts @@ -1,54 +1,32 @@ import '@girs/gjs'; // For global types like `log()` import St from '@girs/st-14'; -import GObject from '@girs/gobject-2.0'; import "@girs/gnome-shell/extensions/global"; // For global shell types import { Extension, gettext as _ } from '@girs/gnome-shell/extensions/extension'; -import * as panelMenu from '@girs/gnome-shell/ui/panelMenu'; -import { PopupMenuItem } from '@girs/gnome-shell/ui/popupMenu'; +import PanelMenu from '@girs/gnome-shell/ui/panelMenu'; import * as Main from '@girs/gnome-shell/ui/main'; -import * as test from '@girs/gnome-shell/extensions'; +export default class ExampleExtension extends Extension { -const PanelMenuButton = panelMenu.Button; + _indicator: PanelMenu.Button; -class TIndicator extends PanelMenuButton { - constructor() { - super(0.0, _('My Shiny Indicator')); - } - _init() { - super._init(0.0, _('My Shiny Indicator')); + enable() { + // Create a panel button + this._indicator = new PanelMenu.Button(0.0, this.metadata.name, false); - this.add_child(new St.Icon({ - iconName: 'face-smile-symbolic', + // Add an icon + const icon = new St.Icon({ + iconName: 'face-laugh-symbolic', styleClass: 'system-status-icon', - })); - - let item = new PopupMenuItem(_('Show Notification')); - item.connect('activate', () => { - Main.notify(_('Hello %s! :)').format("World")); }); + this._indicator.add_child(icon); - this.menu.addMenuItem(item); - } -} - -const Indicator = GObject.registerClass(TIndicator); - -export default class HelloWorldExtension extends Extension { - - _indicator: TIndicator | null = null; - - enable() { - log(`enabling ${JSON.stringify(this.metadata, null, 2)}`); - this._indicator = new Indicator(); + // Add the indicator to the panel Main.panel.addToStatusArea(this.uuid, this._indicator); - log(`enabled test ${typeof test.extension.gettext}`); } disable() { - Main.panel.remove_child(this._indicator); this._indicator?.destroy(); this._indicator = null; } -} +} \ No newline at end of file