Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
JumpLink committed Mar 27, 2024
1 parent e42efd8 commit 3396b8d
Showing 1 changed file with 12 additions and 34 deletions.
46 changes: 12 additions & 34 deletions examples/hello-world/src/extension.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
}

0 comments on commit 3396b8d

Please sign in to comment.