From e178b09a35d72a277608a5cad713090b57a1c669 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryan=20Gald=C3=A1mez?= Date: Thu, 12 Sep 2024 21:26:51 -0600 Subject: [PATCH 1/7] feature(zenThemesImporter): write saved preferences to dom on startup --- src/ZenThemesImporter.mjs | 49 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/ZenThemesImporter.mjs b/src/ZenThemesImporter.mjs index 257e2b1..a5fbe63 100644 --- a/src/ZenThemesImporter.mjs +++ b/src/ZenThemesImporter.mjs @@ -36,8 +36,9 @@ var gZenThemeImporter = new (class { constructor() { console.info('ZenThemeImporter: Initiating Zen theme importer'); try { - window.SessionStore.promiseInitialized.then(() => { + window.SessionStore.promiseInitialized.then(async () => { this.insertStylesheet(); + await this.writeToDom(); }); console.info('ZenThemeImporter: Zen theme imported'); } catch (e) { @@ -108,9 +109,55 @@ var gZenThemeImporter = new (class { async updateStylesheet() { this.removeStylesheet(); await this.writeStylesheet(); + await this.writeToDom(); this.insertStylesheet(); } + _getBrowser() { + if (!this.__browser) { + this.__browser = Services.wm.getMostRecentWindow("navigator:browser") + } + + return this.__browser + } + + async _getThemePreferences(theme) { + const themePath = PathUtils.join(this.getThemeFolder(theme), 'preferences.json'); + + if (!(await IOUtils.exists(themePath)) || !theme.preferences) { + return []; + } + + return IOUtils.readJSON(themePath); + } + + async writeToDom() { + const browser = this._getBrowser() + + for (const theme of Object.values(await this.getThemes())) { + const themePreferences = (await this._getThemePreferences(theme)).filter(({ type }) => type === "dropdown") + + for (const { property } of themePreferences) { + const value = Services.prefs.getStringPref(property, "") + + if (value !== "") { + let element = browser.document.getElementById(theme.name) + + if (!element) { + element = browser.document.createElement("div") + + element.style.display = "none" + element.setAttribute("id", theme.name) + + browser.document.body.appendChild(element) + } + + element.setAttribute(property, value) + } + } + } + } + async writeStylesheet() { const themes = []; this._themes = null; From 4cedd84ac877b4ebdf807eb2991cacfa754e8ac1 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Fri, 13 Sep 2024 20:12:05 +0200 Subject: [PATCH 2/7] Refactor ZenWorkspaces.mjs to add createContainerTabMenu method --- src/ZenWorkspaces.mjs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b95a246..b45e999 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -683,6 +683,20 @@ var ZenWorkspaces = { }, // Tab browser utilities + createContainerTabMenu(event) { + let window = event.target.ownerGlobal; + const workspace = this.getActiveWorkspaceFromCache(); + if (!workspace) { + return; + } + let containerTabId = workspace.containerTabId; + return window.createUserContextMenu(event, { + isContextMenu: true, + excludeUserContextId: containerTabId, + showDefaultTab: true, + }); + }, + getContextIdIfNeeded(userContextId) { if (typeof userContextId !== "undefined" || !this.workspaceEnabled) { return [userContextId, false]; From 5a9fb8d7be23cfe72f3a80768355a325f84788bd Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Fri, 13 Sep 2024 22:52:03 +0200 Subject: [PATCH 3/7] Allow pinned tabs to be workspace specific --- src/ZenWorkspaces.mjs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b45e999..b5d9f73 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -1,3 +1,4 @@ + var ZenWorkspaces = { async init() { let docElement = document.documentElement; @@ -95,7 +96,7 @@ var ZenWorkspaces = { if (tabs.length === 1) { this._createNewTabForWorkspace({ uuid: workspaceID }); // We still need to close other tabs in the workspace - this.changeWorkspace({ uuid: workspaceID }); + this.changeWorkspace({ uuid: workspaceID }, true); } } }, @@ -469,10 +470,15 @@ var ZenWorkspaces = { button.removeAttribute('disabled'); }, + get _shouldAllowPinTab() { + return Services.prefs.getBoolPref('zen.workspaces.individual-pinned-tabs'); + }, + async changeWorkspace(window, onInit = false) { if (!this.workspaceEnabled) { return; } + const shouldAllowPinnedTabs = this._shouldAllowPinTab; let firstTab = undefined; let workspaces = await this._workspaces(); for (let workspace of workspaces.workspaces) { @@ -481,7 +487,7 @@ var ZenWorkspaces = { this.unsafeSaveWorkspaces(workspaces); console.info('ZenWorkspaces: Changing workspace to', window.uuid); for (let tab of gBrowser.tabs) { - if ((tab.getAttribute('zen-workspace-id') === window.uuid && !tab.pinned) || !tab.hasAttribute('zen-workspace-id')) { + if ((tab.getAttribute('zen-workspace-id') === window.uuid && !(tab.pinned && !shouldAllowPinnedTabs)) || !tab.hasAttribute('zen-workspace-id')) { if (!firstTab) { firstTab = tab; } else if (gBrowser.selectedTab === tab) { @@ -504,7 +510,7 @@ var ZenWorkspaces = { } for (let tab of gBrowser.tabs) { if (tab.getAttribute('zen-workspace-id') !== window.uuid) { - gBrowser.hideTab(tab); + gBrowser.hideTab(tab, undefined, shouldAllowPinnedTabs); } } document.documentElement.setAttribute('zen-workspace-id', window.uuid); @@ -512,6 +518,8 @@ var ZenWorkspaces = { await this._updateWorkspacesButton(); await this._propagateWorkspaceData(); await this._updateWorkspacesChangeContextMenu(); + + document.getElementById('tabbrowser-tabs')._positionPinnedTabs(); }, async _updateWorkspacesChangeContextMenu() { From cc4601f0e1460cad750e686f25ac8250519e34e8 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Fri, 13 Sep 2024 23:01:22 +0200 Subject: [PATCH 4/7] Fixed display when choosing containers for each workspace --- src/ZenWorkspaces.mjs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index b5d9f73..14bdfa9 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -693,10 +693,7 @@ var ZenWorkspaces = { // Tab browser utilities createContainerTabMenu(event) { let window = event.target.ownerGlobal; - const workspace = this.getActiveWorkspaceFromCache(); - if (!workspace) { - return; - } + const workspace = this._workspaceCache.workspaces.find((workspace) => this._contextMenuId === workspace.uuid); let containerTabId = workspace.containerTabId; return window.createUserContextMenu(event, { isContextMenu: true, From d0f32a6ee83c7d3515457687a9c7b7a032d03cd3 Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Sat, 14 Sep 2024 09:05:38 +0200 Subject: [PATCH 5/7] Refactor ZenWorkspaces.mjs to preserve full icons instead of just the first character --- src/ZenWorkspaces.mjs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 14bdfa9..36f3bd0 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -101,9 +101,7 @@ var ZenWorkspaces = { } }, - // Convert all the icons to just the first character, just in case someone - // decides to use a string with more than one character - _kIcons: JSON.parse(Services.prefs.getStringPref("zen.workspaces.icons")).map((icon) => icon[0]), + _kIcons: JSON.parse(Services.prefs.getStringPref("zen.workspaces.icons")).map((icon) => icon), _initializeWorkspaceCreationIcons() { let container = document.getElementById('PanelUI-zen-workspaces-create-icons-container'); From c5619a7dc93d5db06cdc20a83343c03e4289a0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bryan=20Gald=C3=A1mez?= Date: Sat, 14 Sep 2024 03:07:44 -0600 Subject: [PATCH 6/7] feature(zenThemesImporter): add compatibility mode with legacy preferences --- src/ZenThemesImporter.mjs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/ZenThemesImporter.mjs b/src/ZenThemesImporter.mjs index a5fbe63..7b1d957 100644 --- a/src/ZenThemesImporter.mjs +++ b/src/ZenThemesImporter.mjs @@ -125,17 +125,30 @@ var gZenThemeImporter = new (class { const themePath = PathUtils.join(this.getThemeFolder(theme), 'preferences.json'); if (!(await IOUtils.exists(themePath)) || !theme.preferences) { - return []; + return { preferences: [], isLegacyMode: false }; } - return IOUtils.readJSON(themePath); + let preferences = await IOUtils.readJSON(themePath); + + // skip transformation, we won't be writing old preferences to dom, all of them can only be checkboxes + if (typeof preferences === "object" && !Array.isArray(preferences)) { + return { preferences: [], areOldPreferences: true }; + } + + return { preferences, areOldPreferences: false }; } async writeToDom() { const browser = this._getBrowser() for (const theme of Object.values(await this.getThemes())) { - const themePreferences = (await this._getThemePreferences(theme)).filter(({ type }) => type === "dropdown") + const { preferences, areOldPreferences } = await this._getThemePreferences(theme); + + if (areOldPreferences) { + continue; + } + + const themePreferences = preferences.filter(({ type }) => type === "dropdown") for (const { property } of themePreferences) { const value = Services.prefs.getStringPref(property, "") From 62c056b4d00c6426083ea23ed27f170b72ea145f Mon Sep 17 00:00:00 2001 From: mauro-balades Date: Sat, 14 Sep 2024 11:34:26 +0200 Subject: [PATCH 7/7] Refactor ZenWorkspaces.mjs to discard unloaded tabs when hiding workspace --- src/ZenWorkspaces.mjs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 36f3bd0..ece391a 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -508,6 +508,8 @@ var ZenWorkspaces = { } for (let tab of gBrowser.tabs) { if (tab.getAttribute('zen-workspace-id') !== window.uuid) { + // FOR UNLOADING TABS: + // gBrowser.discardBrowser(tab, true); gBrowser.hideTab(tab, undefined, shouldAllowPinnedTabs); } }