From 0f775df5e64bfd41bfbbdf857a21fc5f92a44804 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Wed, 18 Sep 2024 00:06:02 +0200 Subject: [PATCH] Refactor ZenWorkspaces initialization and workspace check --- src/ZenWorkspaces.mjs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b30371c..09ae4b1 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -5,13 +5,8 @@ var ZenWorkspaces = { */ _lastSelectedWorkspaceTabs: {}, - async init() { - let docElement = document.documentElement; - if ( - docElement.getAttribute('chromehidden').includes('toolbar') || - docElement.getAttribute('chromehidden').includes('menubar') || - docElement.hasAttribute('privatebrowsingmode') - ) { + init() { + if (!this.shouldHaveWorkspaces) { console.warn('ZenWorkspaces: !!! ZenWorkspaces is disabled in hidden windows !!!'); return; // We are in a hidden window, don't initialize ZenWorkspaces } @@ -22,8 +17,19 @@ var ZenWorkspaces = { }); }, + get shouldHaveWorkspaces() { + delete this.shouldHaveWorkspaces; + let docElement = document.documentElement; + this.shouldHaveWorkspaces = !(docElement.hasAttribute('privatebrowsingmode') + || docElement.getAttribute('chromehidden').includes('toolbar') + || docElement.getAttribute('chromehidden').includes('menubar')); + return this.shouldHaveWorkspaces; + }, + get workspaceEnabled() { - return Services.prefs.getBoolPref('zen.workspaces.enabled', false); + delete this.workspaceEnabled; + this.workspaceEnabled = Services.prefs.getBoolPref('zen.workspaces.enabled', false) && this.shouldHaveWorkspaces; + return this.workspaceEnabled; }, getActiveWorkspaceFromCache() { @@ -744,4 +750,3 @@ var ZenWorkspaces = { }, }; -ZenWorkspaces.init();