Move the indicator to another file

This commit is contained in:
2023-05-13 16:22:29 +09:00
parent 7286c71da5
commit ff369047d0
2 changed files with 55 additions and 30 deletions
+4 -30
View File
@@ -9,52 +9,26 @@ const PanelMenu = imports.ui.panelMenu;
const State = Me.imports.sources.state;
const Renderer = Me.imports.sources.renderer;
const Keybinds = Me.imports.sources.keybinds;
const Indicator = Me.imports.sources.indicator;
class Extension {
constructor() {
this._state = new State.StateManager();
this._renderer = new Renderer.Renderer(this._state);
this._keybinds = new Keybinds.KeyboardManager(this._state, this._renderer);
this._layoutIndicator = null;
this._indicator = new Indicator.Indicator(this._state, this._renderer);
}
enable() {
this._renderer.enable();
this._keybinds.enable();
this.settings = ExtensionUtils.getSettings(
"org.gnome.shell.extensions.fairy"
);
let indicatorName = `${Me.metadata.name} Layout Indicator`;
this._layoutIndicator = new PanelMenu.Button(0.0, indicatorName, false);
// Add an icon
let icon = new St.Icon({
gicon: new Gio.ThemedIcon({ name: "face-laugh-symbolic" }),
style_class: "system-status-icon",
});
this._layoutIndicator.add_child(icon);
this.settings.bind(
"show-layout",
this._layoutIndicator,
"visible",
Gio.SettingsBindFlags.DEFAULT
);
Main.panel.addToStatusArea(indicatorName, this._layoutIndicator);
this._indicator.enable();
}
disable() {
this._renderer.disable();
this._keybinds.disable();
this._layoutIndicator.destroy();
this._layoutIndicator = null;
this.settings = null;
this._indicator.disable();
}
}
+51
View File
@@ -0,0 +1,51 @@
"use strict";
const GObject = imports.gi.GObject;
const Main = imports.ui.main;
const Meta = imports.gi.Meta;
const Shell = imports.gi.Shell;
const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
var Indicator = GObject.registerClass(
class Indicator extends GObject.Object {
_init(state, renderer) {
super._init();
this._state = state;
this._renderer = renderer;
}
enable() {
this.settings = ExtensionUtils.getSettings(
"org.gnome.shell.extensions.fairy"
);
let indicatorName = `${Me.metadata.name} Indicator`;
this._layoutIndicator = new PanelMenu.Button(0.0, indicatorName, false);
// Add an icon
let icon = new St.Icon({
gicon: new Gio.ThemedIcon({ name: "face-laugh-symbolic" }),
style_class: "system-status-icon",
});
this._layoutIndicator.add_child(icon);
this.settings.bind(
"show-layout",
this._layoutIndicator,
"visible",
Gio.SettingsBindFlags.DEFAULT
);
Main.panel.addToStatusArea(indicatorName, this._layoutIndicator);
}
disable() {
this._layoutIndicator.destroy();
this._layoutIndicator = null;
this.settings = null;
}
}
);