diff --git a/extension.js b/extension.js index 68706f4..d90c868 100644 --- a/extension.js +++ b/extension.js @@ -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(); } } diff --git a/sources/indicator.js b/sources/indicator.js new file mode 100644 index 0000000..84012a3 --- /dev/null +++ b/sources/indicator.js @@ -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; + } + } +);