diff options
Diffstat (limited to '')
-rw-r--r-- | extensions/44/vertical-workspaces/lib/workspaceSwitcherPopup.js | 75 |
1 files changed, 47 insertions, 28 deletions
diff --git a/extensions/44/vertical-workspaces/lib/workspaceSwitcherPopup.js b/extensions/44/vertical-workspaces/lib/workspaceSwitcherPopup.js index 972f35e..5bde6d0 100644 --- a/extensions/44/vertical-workspaces/lib/workspaceSwitcherPopup.js +++ b/extensions/44/vertical-workspaces/lib/workspaceSwitcherPopup.js @@ -13,52 +13,71 @@ const Main = imports.ui.main; const WorkspaceSwitcherPopup = imports.ui.workspaceSwitcherPopup; -const ExtensionUtils = imports.misc.extensionUtils; -const Me = ExtensionUtils.getCurrentExtension(); +let Me; +let opt; -const _Util = Me.imports.lib.util; -let _overrides; +var WorkspaceSwitcherPopupModule = class { + constructor(me) { + Me = me; + opt = Me.opt; -let opt; -let _firstRun = true; + this._firstActivation = true; + this.moduleEnabled = false; + this._overrides = null; + } -function update(reset = false) { - opt = Me.imports.lib.settings.opt; - const moduleEnabled = opt.get('workspaceSwitcherPopupModule', true); - reset = reset || !moduleEnabled; + cleanGlobals() { + Me = null; + opt = null; + } - // don't even touch this module if disabled - if (_firstRun && reset) - return; + update(reset) { + this.moduleEnabled = opt.get('workspaceSwitcherPopupModule'); + const conflict = Me.Util.getEnabledExtensions('workspace-switcher-manager').length || + Me.Util.getEnabledExtensions('WsSwitcherPopupManager').length; - _firstRun = false; + if (conflict && !reset) + console.warn(`[${Me.metadata.name}] Warning: "WorkspaceSwitcherPopup" module disabled due to potential conflict with another extension`); - if (_overrides) - _overrides.removeAll(); + reset = reset || !this.moduleEnabled || conflict; - if (reset) { - _overrides = null; - opt = null; - return; + // don't touch original code if module disabled + if (reset && !this._firstActivation) { + this._disableModule(); + } else if (!reset) { + this._firstActivation = false; + this._activateModule(); + } + if (reset && this._firstActivation) + console.debug(' WorkspaceSwitcherPopupModule - Keeping untouched'); } - _overrides = new _Util.Overrides(); + _activateModule() { + if (!this._overrides) + this._overrides = new Me.Util.Overrides(); - const enabled = global.settings.get_strv('enabled-extensions'); - const allowWsPopupInjection = !(enabled.includes('workspace-switcher-manager@G-dH.github.com') || enabled.includes('WsSwitcherPopupManager@G-dH.github.com-dev')); - if (allowWsPopupInjection) { // 1-VERTICAL, 0-HORIZONTAL - _overrides.addOverride('WorkspaceSwitcherPopup', WorkspaceSwitcherPopup.WorkspaceSwitcherPopup.prototype, WorkspaceSwitcherPopupOverride); + this._overrides.addOverride('WorkspaceSwitcherPopup', WorkspaceSwitcherPopup.WorkspaceSwitcherPopup.prototype, WorkspaceSwitcherPopupCommon); + console.debug(' WorkspaceSwitcherPopupModule - Activated'); } -} -const WorkspaceSwitcherPopupOverride = { + _disableModule() { + if (this._overrides) + this._overrides.removeAll(); + this._overrides = null; + + console.debug(' WorkspaceSwitcherPopupModule - Disabled'); + } +}; + +const WorkspaceSwitcherPopupCommon = { // injection to _init() after__init() { if (opt.ORIENTATION) { // 1-VERTICAL, 0-HORIZONTAL this._list.vertical = true; } this._list.set_style('margin: 0;'); - this.remove_constraint(this.get_constraints()[0]); + if (this.get_constraints()[0]) + this.remove_constraint(this.get_constraints()[0]); }, // injection to display() |