From 81e854a89f57862623c65c1fe4c70dc6507de6bd Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Wed, 27 Aug 2025 23:25:07 +0200 Subject: [PATCH 01/18] feat: Full cross-window workspace syncing, b=no-bug, c=workspaces --- src/browser/base/content/zen-assets.inc.xhtml | 1 + .../base/content/zen-assets.jar.inc.mn | 1 + src/zen/workspaces/ZenWindowSyncing.mjs | 226 ++++++++++++++++++ 3 files changed, 228 insertions(+) create mode 100644 src/zen/workspaces/ZenWindowSyncing.mjs diff --git a/src/browser/base/content/zen-assets.inc.xhtml b/src/browser/base/content/zen-assets.inc.xhtml index 0756714ea..d94a632dd 100644 --- a/src/browser/base/content/zen-assets.inc.xhtml +++ b/src/browser/base/content/zen-assets.inc.xhtml @@ -58,3 +58,4 @@ + diff --git a/src/browser/base/content/zen-assets.jar.inc.mn b/src/browser/base/content/zen-assets.jar.inc.mn index 4c341e4e1..78d3f4bbd 100644 --- a/src/browser/base/content/zen-assets.jar.inc.mn +++ b/src/browser/base/content/zen-assets.jar.inc.mn @@ -44,6 +44,7 @@ content/browser/zen-components/ZenWorkspaceIcons.mjs (../../zen/workspaces/ZenWorkspaceIcons.mjs) content/browser/zen-components/ZenWorkspace.mjs (../../zen/workspaces/ZenWorkspace.mjs) content/browser/zen-components/ZenWorkspaces.mjs (../../zen/workspaces/ZenWorkspaces.mjs) + content/browser/zen-components/ZenWindowSyncing.mjs (../../zen/workspaces/ZenWindowSyncing.mjs) content/browser/zen-components/ZenWorkspaceCreation.mjs (../../zen/workspaces/ZenWorkspaceCreation.mjs) content/browser/zen-components/ZenWorkspacesStorage.mjs (../../zen/workspaces/ZenWorkspacesStorage.mjs) content/browser/zen-components/ZenWorkspacesSync.mjs (../../zen/workspaces/ZenWorkspacesSync.mjs) diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs new file mode 100644 index 000000000..19fbf09f4 --- /dev/null +++ b/src/zen/workspaces/ZenWindowSyncing.mjs @@ -0,0 +1,226 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +{ + class nsZenWorkspaceWindowSync extends nsZenMultiWindowFeature { + #ignoreNextEvents = false; + #waitForPromise = null; + + constructor() { + super(); + if (!window.closed) { + this.init(); + } + } + + async init() { + await gZenWorkspaces.promiseInitialized; + this.#makeSureAllTabsHaveIds(); + this.#setUpEventListeners(); + } + + #makeSureAllTabsHaveIds() { + const allTabs = gZenWorkspaces.allStoredTabs; + for (const tab of allTabs) { + if (!tab.hasAttribute('zen-sync-id')) { + const tabId = gZenUIManager.generateUuidv4(); + tab.setAttribute('zen-sync-id', tabId); + } + } + } + + #setUpEventListeners() { + const kEvents = [ + 'TabClose', + 'TabOpen', + 'TabPinned', + 'TabUnpinned', + 'TabAddedToEssentials', + 'TabRemovedFromEssentials', + 'TabHide', + 'TabShow', + 'TabMove', + ]; + const eventListener = this.#handleEvent.bind(this); + for (const event of kEvents) { + window.addEventListener(event, eventListener); + } + + window.addEventListener('unload', () => { + for (const event of kEvents) { + window.removeEventListener(event, eventListener); + } + }); + } + + #handleEvent(event) { + this.#propagateToOtherWindows(event); + } + + async #propagateToOtherWindows(event) { + if (this.#ignoreNextEvents) { + return; + } + if (this.#waitForPromise) { + await this.#waitForPromise; + } + this.#waitForPromise = new Promise(async (resolve) => { + await this.foreachWindowAsActive(async (browser) => { + if (browser.gZenWorkspaceWindowSync && !this.windowIsActive(browser)) { + await browser.gZenWorkspaceWindowSync.onExternalTabEvent(event); + } + }); + resolve(); + }); + } + + async onExternalTabEvent(event) { + this.#ignoreNextEvents = true; + switch (event.type) { + case 'TabClose': + this.#onTabClose(event); + break; + case 'TabOpen': + await this.#onTabOpen(event); + break; + case 'TabPinned': + this.#onTabPinned(event); + break; + case 'TabUnpinned': + this.#onTabUnpinned(event); + break; + case 'TabAddedToEssentials': + this.#onTabAddedToEssentials(event); + break; + case 'TabRemovedFromEssentials': + this.#onTabRemovedFromEssentials(event); + break; + case 'TabHide': + this.#onTabHide(event); + break; + case 'TabShow': + this.#onTabShow(event); + break; + case 'TabMove': + this.#onTabMove(event); + break; + default: + console.warn(`Unhandled event type: ${event.type}`); + break; + } + this.#ignoreNextEvents = false; + } + + #getTabId(tab) { + return tab.getAttribute('zen-sync-id'); + } + + #getTabWithId(tabId) { + for (const tab of gZenWorkspaces.allStoredTabs) { + if (this.#getTabId(tab) === tabId) { + return tab; + } + } + return null; + } + + #onTabClose(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToClose = this.#getTabWithId(tabId); + if (tabToClose) { + gBrowser.removeTab(tabToClose); + } + } + + #onTabPinned(event) { + const targetTab = event.target; + if (targetTab.hasAttribute('zen-essential')) { + return this.#onTabAddedToEssentials(event); + } + const tabId = this.#getTabId(targetTab); + const elementIndex = targetTab.elementIndex; + const tabToPin = this.#getTabWithId(tabId); + if (tabToPin) { + gBrowser.pinTab(tabToPin); + gBrowser.moveTabTo(tabToPin, { elementIndex, forceUngrouped: !!targetTab.group }); + } + } + + #onTabUnpinned(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToUnpin = this.#getTabWithId(tabId); + if (tabToUnpin) { + gBrowser.unpinTab(tabToUnpin); + } + } + + #onTabAddedToEssentials(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToAdd = this.#getTabWithId(tabId); + if (tabToAdd) { + gZenPinnedTabManager.addToEssentials(tabToAdd); + } + } + + #onTabRemovedFromEssentials(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToRemove = this.#getTabWithId(tabId); + if (tabToRemove) { + gZenPinnedTabManager.removeFromEssentials(tabToRemove); + } + } + + #onTabHide(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToHide = this.#getTabWithId(tabId); + if (tabToHide) { + gBrowser.hideTab(tabToHide); + } + } + + #onTabShow(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const tabToShow = this.#getTabWithId(tabId); + if (tabToShow) { + gBrowser.showTab(tabToShow); + } + } + + #onTabMove(event) { + const targetTab = event.target; + const tabId = this.#getTabId(targetTab); + const elementIndex = targetTab.elementIndex; + const tabToMove = this.#getTabWithId(tabId); + if (tabToMove) { + gBrowser.moveTabTo(tabToMove, { elementIndex, forceUngrouped: !!targetTab.group }); + } + } + + async #onTabOpen(event) { + await new Promise((resolve) => { + const targetTab = event.target; + const isPinned = targetTab.pinned; + const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); + const elementIndex = targetTab.elementIndex; + + const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0, true); + if (isEssential) { + gZenPinnedTabManager.addToEssentials(duplicatedTab); + } else if (isPinned) { + gBrowser.pinTab(duplicatedTab); + } + + gBrowser.moveTabTo(duplicatedTab, { elementIndex, forceUngrouped: !!targetTab.group }); + resolve(); + }); + } + } + + window.gZenWorkspaceWindowSync = new nsZenWorkspaceWindowSync(); +} From 7a4cdaa45cbb98b4420eec8232787a803bc1b943 Mon Sep 17 00:00:00 2001 From: "mr. m" Date: Mon, 1 Sep 2025 16:09:59 +0200 Subject: [PATCH 02/18] feat: Also change icons and labels if the tab is pending, b=no-bug, c=tabs, workspaces --- src/zen/tabs/ZenPinnedTabManager.mjs | 2 ++ src/zen/workspaces/ZenWindowSyncing.mjs | 30 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index 408481622..3f3ca4736 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -92,6 +92,7 @@ } onTabIconChanged(tab, url = null) { + tab.dispatchEvent(new CustomEvent('ZenTabIconChanged', { bubbles: true, detail: { tab } })); const iconUrl = url ?? tab.iconImage.src; if (!iconUrl && tab.hasAttribute('zen-pin-id')) { try { @@ -1436,6 +1437,7 @@ } async onTabLabelChanged(tab) { + tab.dispatchEvent(new CustomEvent('ZenTabLabelChanged', { detail: { tab } })); if (!this._pinsCache) { return; } diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs index 19fbf09f4..bcb63d8f4 100644 --- a/src/zen/workspaces/ZenWindowSyncing.mjs +++ b/src/zen/workspaces/ZenWindowSyncing.mjs @@ -40,6 +40,8 @@ 'TabHide', 'TabShow', 'TabMove', + 'ZenTabIconChanged', + 'ZenTabLabelChanged', ]; const eventListener = this.#handleEvent.bind(this); for (const event of kEvents) { @@ -104,6 +106,12 @@ case 'TabMove': this.#onTabMove(event); break; + case 'ZenTabIconChanged': + this.#onTabIconChanged(event); + break; + case 'ZenTabLabelChanged': + this.#onTabLabelChanged(event); + break; default: console.warn(`Unhandled event type: ${event.type}`); break; @@ -156,6 +164,26 @@ } } + #onTabIconChanged(event) { + this.#updateTabIconAndLabel(event); + } + + #onTabLabelChanged(event) { + this.#updateTabIconAndLabel(event); + } + + #updateTabIconAndLabel(event) { + const targetTab = event.target; + if (targetTab.hasAttribute("pending")) { + const tabId = this.#getTabId(targetTab); + const tabToChange = this.#getTabWithId(tabId); + if (tabToChange) { + gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab)); + gBrowser._setTabLabel(tabToChange, targetTab.label); + } + } + } + #onTabAddedToEssentials(event) { const targetTab = event.target; const tabId = this.#getTabId(targetTab); @@ -209,7 +237,7 @@ const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); const elementIndex = targetTab.elementIndex; - const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0, true); + const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0); if (isEssential) { gZenPinnedTabManager.addToEssentials(duplicatedTab); } else if (isPinned) { From 91f5d58fbc1c62f415ea6ee4e5e7f69afe2705fa Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Tue, 2 Sep 2025 16:21:04 +0200 Subject: [PATCH 03/18] feat: Dont session duplicate the tabs, b=no-bug, c=workspaces --- src/zen/workspaces/ZenWindowSyncing.mjs | 55 +++++++++++++------------ 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs index bcb63d8f4..da5de683b 100644 --- a/src/zen/workspaces/ZenWindowSyncing.mjs +++ b/src/zen/workspaces/ZenWindowSyncing.mjs @@ -66,13 +66,14 @@ if (this.#waitForPromise) { await this.#waitForPromise; } - this.#waitForPromise = new Promise(async (resolve) => { - await this.foreachWindowAsActive(async (browser) => { + this.#waitForPromise = new Promise((resolve) => { + this.foreachWindowAsActive(async (browser) => { if (browser.gZenWorkspaceWindowSync && !this.windowIsActive(browser)) { await browser.gZenWorkspaceWindowSync.onExternalTabEvent(event); } + }).then(() => { + resolve(); }); - resolve(); }); } @@ -174,13 +175,11 @@ #updateTabIconAndLabel(event) { const targetTab = event.target; - if (targetTab.hasAttribute("pending")) { - const tabId = this.#getTabId(targetTab); - const tabToChange = this.#getTabWithId(tabId); - if (tabToChange) { - gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab)); - gBrowser._setTabLabel(tabToChange, targetTab.label); - } + const tabId = this.#getTabId(targetTab); + const tabToChange = this.#getTabWithId(tabId); + if (tabToChange && tabToChange.hasAttribute('pending')) { + gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab)); + gBrowser._setTabLabel(tabToChange, targetTab.label); } } @@ -223,30 +222,34 @@ #onTabMove(event) { const targetTab = event.target; const tabId = this.#getTabId(targetTab); - const elementIndex = targetTab.elementIndex; + const tabIndex = targetTab._pPos; const tabToMove = this.#getTabWithId(tabId); if (tabToMove) { - gBrowser.moveTabTo(tabToMove, { elementIndex, forceUngrouped: !!targetTab.group }); + gBrowser.moveTabTo(tabToMove, { tabIndex, forceUngrouped: !!targetTab.group }); } } async #onTabOpen(event) { - await new Promise((resolve) => { - const targetTab = event.target; - const isPinned = targetTab.pinned; - const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); - const elementIndex = targetTab.elementIndex; + const targetTab = event.target; + const isPinned = targetTab.pinned; + const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); + const elementIndex = targetTab.elementIndex; - const duplicatedTab = SessionStore.duplicateTab(window, targetTab, 0); - if (isEssential) { - gZenPinnedTabManager.addToEssentials(duplicatedTab); - } else if (isPinned) { - gBrowser.pinTab(duplicatedTab); - } - - gBrowser.moveTabTo(duplicatedTab, { elementIndex, forceUngrouped: !!targetTab.group }); - resolve(); + const duplicatedTab = gBrowser.addTrustedTab(targetTab.linkedBrowser.currentURI.spec, { + createLazyBrowser: true, }); + + duplicatedTab.setAttribute('zen-pin-id', targetTab.getAttribute('zen-pin-id')); + duplicatedTab.setAttribute('zen-tab-id', targetTab.getAttribute('zen-tab-id')); + duplicatedTab.setAttribute('zen-workspace-id', targetTab.getAttribute('zen-workspace-id')); + + if (isEssential) { + gZenPinnedTabManager.addToEssentials(duplicatedTab); + } else if (isPinned) { + gBrowser.pinTab(duplicatedTab); + } + + gBrowser.moveTabTo(duplicatedTab, { elementIndex, forceUngrouped: !!targetTab.group }); } } From a55b1c7495cf1e1daa3bea602ef5a7f71cc7daeb Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sat, 27 Sep 2025 17:54:28 +0200 Subject: [PATCH 04/18] feat: Properly handle tab moves, b=no-bug, c=workspaces --- src/zen/workspaces/ZenWindowSyncing.mjs | 83 ++++++++++++++++++++----- 1 file changed, 67 insertions(+), 16 deletions(-) diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs index da5de683b..857f9fc9c 100644 --- a/src/zen/workspaces/ZenWindowSyncing.mjs +++ b/src/zen/workspaces/ZenWindowSyncing.mjs @@ -22,7 +22,7 @@ #makeSureAllTabsHaveIds() { const allTabs = gZenWorkspaces.allStoredTabs; for (const tab of allTabs) { - if (!tab.hasAttribute('zen-sync-id')) { + if (!tab.hasAttribute('zen-sync-id') && !tab.hasAttribute('zen-empty-tab')) { const tabId = gZenUIManager.generateUuidv4(); tab.setAttribute('zen-sync-id', tabId); } @@ -33,15 +33,25 @@ const kEvents = [ 'TabClose', 'TabOpen', + 'TabMove', + 'TabPinned', 'TabUnpinned', + 'TabAddedToEssentials', 'TabRemovedFromEssentials', + 'TabHide', 'TabShow', - 'TabMove', + 'ZenTabIconChanged', 'ZenTabLabelChanged', + + 'TabGroupCreate', + 'TabGroupRemoved', + 'TabGrouped', + 'TabUngrouped', + 'TabGroupMoved', ]; const eventListener = this.#handleEvent.bind(this); for (const event of kEvents) { @@ -105,6 +115,7 @@ this.#onTabShow(event); break; case 'TabMove': + case 'TabGroupMoved': this.#onTabMove(event); break; case 'ZenTabIconChanged': @@ -113,6 +124,14 @@ case 'ZenTabLabelChanged': this.#onTabLabelChanged(event); break; + case 'TabGroupCreate': + this.#onTabGroupCreate(event); + break; + case 'TabGroupRemoved': + case 'TabGrouped': + case 'TabUngrouped': + // Tab grouping changes are automatically synced by Firefox + break; default: console.warn(`Unhandled event type: ${event.type}`); break; @@ -222,10 +241,36 @@ #onTabMove(event) { const targetTab = event.target; const tabId = this.#getTabId(targetTab); - const tabIndex = targetTab._pPos; const tabToMove = this.#getTabWithId(tabId); + const workspaceId = targetTab.getAttribute('zen-workspace-id'); + const isEssential = targetTab.hasAttribute('zen-essential'); if (tabToMove) { - gBrowser.moveTabTo(tabToMove, { tabIndex, forceUngrouped: !!targetTab.group }); + let tabSibling = targetTab.previousElementSibling; + let isFirst = false; + if (!tabSibling?.hasAttribute('zen-sync-id')) { + isFirst = true; + } + gBrowser.zenHandleTabMove(tabToMove, () => { + if (isFirst) { + let container; + if (isEssential) { + container = gZenWorkspaces.getEssentialsSection(tabToMove); + } else { + const workspaceElement = gZenWorkspaces.workspaceElement(workspaceId); + container = tabToMove.pinned + ? workspaceElement.pinnedTabsContainer + : workspaceElement.tabsContainer; + } + container.insertBefore(tabToMove, container.firstChild); + } else { + let relativeTab = gZenWorkspaces.allStoredTabs.find((tab) => { + return this.#getTabId(tab) === this.#getTabId(tabSibling); + }); + if (relativeTab) { + relativeTab.after(tabToMove); + } + } + }); } } @@ -233,23 +278,29 @@ const targetTab = event.target; const isPinned = targetTab.pinned; const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); - const elementIndex = targetTab.elementIndex; - + if (!this.#getTabId(targetTab) && !targetTab.hasAttribute('zen-empty-tab')) { + const tabId = gZenUIManager.generateUuidv4(); + targetTab.setAttribute('zen-sync-id', tabId); + } const duplicatedTab = gBrowser.addTrustedTab(targetTab.linkedBrowser.currentURI.spec, { createLazyBrowser: true, + essential: isEssential, + pinned: isPinned, }); - - duplicatedTab.setAttribute('zen-pin-id', targetTab.getAttribute('zen-pin-id')); - duplicatedTab.setAttribute('zen-tab-id', targetTab.getAttribute('zen-tab-id')); - duplicatedTab.setAttribute('zen-workspace-id', targetTab.getAttribute('zen-workspace-id')); - - if (isEssential) { - gZenPinnedTabManager.addToEssentials(duplicatedTab); - } else if (isPinned) { - gBrowser.pinTab(duplicatedTab); + if (!isEssential) { + gZenWorkspaces.moveTabToWorkspace( + duplicatedTab, + targetTab.getAttribute('zen-workspace-id') + ); } + duplicatedTab.setAttribute('zen-pin-id', targetTab.getAttribute('zen-pin-id')); + duplicatedTab.setAttribute('zen-sync-id', targetTab.getAttribute('zen-sync-id')); + } - gBrowser.moveTabTo(duplicatedTab, { elementIndex, forceUngrouped: !!targetTab.group }); + #onTabGroupCreate(event) { + const targetGroup = event.target; + const isSplitView = targetGroup.classList.contains('zen-split-view'); + const isFolder = targetGroup.isZenFolder; } } From 86006c889149bf4d44ea166637b859242f56194f Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sun, 28 Sep 2025 23:45:13 +0200 Subject: [PATCH 05/18] feat: Start on new session restore, b=no-bug, c=no-component --- prefs/browser.yaml | 3 +- src/zen/sessionstore/ZenSessionFile.sys.mjs | 27 ++++++++++ .../sessionstore/ZenSessionManager.sys.mjs | 50 +++++++++++++++++++ src/zen/sessionstore/ZenSessionWindow.sys.mjs | 35 +++++++++++++ 4 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 src/zen/sessionstore/ZenSessionFile.sys.mjs create mode 100644 src/zen/sessionstore/ZenSessionManager.sys.mjs create mode 100644 src/zen/sessionstore/ZenSessionWindow.sys.mjs diff --git a/prefs/browser.yaml b/prefs/browser.yaml index 30aa603e9..f76c33f5c 100644 --- a/prefs/browser.yaml +++ b/prefs/browser.yaml @@ -3,7 +3,8 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. - name: browser.startup.page - value: 3 + value: 0 + locked: true - name: browser.sessionstore.restore_pinned_tabs_on_demand value: true diff --git a/src/zen/sessionstore/ZenSessionFile.sys.mjs b/src/zen/sessionstore/ZenSessionFile.sys.mjs new file mode 100644 index 000000000..c50960ae1 --- /dev/null +++ b/src/zen/sessionstore/ZenSessionFile.sys.mjs @@ -0,0 +1,27 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +const FILE_NAME = 'zen-sessions.jsonlz4'; + +export class nsZenSessionFile { + #path; + + #windows; + + constructor() { + this.#path = PathUtils.join(profileDir, FILE_NAME); + } + + async read() { + try { + return await IOUtils.readJSON(this.#path, { compress: true }); + } catch (e) { + return {}; + } + } + + async write(data) { + await IOUtils.writeJSON(this.#path, data, { compress: true }); + } +} diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs new file mode 100644 index 000000000..68aa829e4 --- /dev/null +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -0,0 +1,50 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +import { + cancelIdleCallback, + clearTimeout, + requestIdleCallback, + setTimeout, +} from 'resource://gre/modules/Timer.sys.mjs'; + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + ZenSessionFile: 'resource://gre/modules/ZenSessionFile.sys.mjs', + PrivateBrowsingUtils: 'resource://gre/modules/PrivateBrowsingUtils.sys.mjs', + RunState: 'resource:///modules/sessionstore/RunState.sys.mjs', +}); + +class nsZenSessionManager { + #file; + + constructor() { + this.#file = null; + } + + get file() { + if (!this.#file) { + this.#file = lazy.ZenSessionFile; + } + return this.#file; + } + + /** + * Saves the current session state. Collects data and writes to disk. + * + * @param forceUpdateAllWindows (optional) + * Forces us to recollect data for all windows and will bypass and + * update the corresponding caches. + */ + saveState(forceUpdateAllWindows = false) { + if (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) { + // Don't save (or even collect) anything in permanent private + // browsing mode + return Promise.resolve(); + } + } +} + +export const ZenSessionStore = new nsZenSessionManager(); diff --git a/src/zen/sessionstore/ZenSessionWindow.sys.mjs b/src/zen/sessionstore/ZenSessionWindow.sys.mjs new file mode 100644 index 000000000..460070234 --- /dev/null +++ b/src/zen/sessionstore/ZenSessionWindow.sys.mjs @@ -0,0 +1,35 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +export class ZenSessionWindow { + #id; + #selectedWorkspace; + #selectedTab; + + constructor(id) { + this.#id = id; + this.#selectedWorkspace = null; + this.#selectedTab = null; + } + + get id() { + return this.#id; + } + + get selectedWorkspace() { + return this.#selectedWorkspace; + } + + set selectedWorkspace(workspace) { + this.#selectedWorkspace = workspace; + } + + get selectedTab() { + return this.#selectedTab; + } + + set selectedTab(tab) { + this.#selectedTab = tab; + } +} From 240a031e38195360057ab14aa6900b3932675d4f Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Sat, 18 Oct 2025 19:52:53 +0200 Subject: [PATCH 06/18] Discard changes to prefs/browser.yaml --- prefs/browser.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prefs/browser.yaml b/prefs/browser.yaml index f76c33f5c..30aa603e9 100644 --- a/prefs/browser.yaml +++ b/prefs/browser.yaml @@ -3,8 +3,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. - name: browser.startup.page - value: 0 - locked: true + value: 3 - name: browser.sessionstore.restore_pinned_tabs_on_demand value: true From 79ff574978de1c5f723eb6515fccaf0d1ffa7baf Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Wed, 29 Oct 2025 23:57:20 +0100 Subject: [PATCH 07/18] feat: Start doing out own session restore, b=no-bug, c=folders, tabs --- .../sessionstore/SessionFile-sys-mjs.patch | 21 ++ .../sessionstore/SessionStartup-sys-mjs.patch | 21 ++ .../sessionstore/SessionStore-sys-mjs.patch | 51 +++-- src/zen/ZenComponents.manifest | 15 ++ src/zen/folders/ZenFolder.mjs | 2 - src/zen/moz.build | 5 + .../sessionstore/SessionComponents.manifest | 6 + src/zen/sessionstore/ZenSessionFile.sys.mjs | 39 ++-- .../sessionstore/ZenSessionManager.sys.mjs | 137 ++++++++++++- src/zen/sessionstore/ZenSessionWindow.sys.mjs | 35 ---- src/zen/sessionstore/moz.build | 8 + src/zen/tabs/ZenPinnedTabManager.mjs | 192 +----------------- src/zen/zen.globals.js | 1 - 13 files changed, 267 insertions(+), 266 deletions(-) create mode 100644 src/browser/components/sessionstore/SessionFile-sys-mjs.patch create mode 100644 src/browser/components/sessionstore/SessionStartup-sys-mjs.patch create mode 100644 src/zen/ZenComponents.manifest create mode 100644 src/zen/sessionstore/SessionComponents.manifest delete mode 100644 src/zen/sessionstore/ZenSessionWindow.sys.mjs create mode 100644 src/zen/sessionstore/moz.build diff --git a/src/browser/components/sessionstore/SessionFile-sys-mjs.patch b/src/browser/components/sessionstore/SessionFile-sys-mjs.patch new file mode 100644 index 000000000..04aa6f0ca --- /dev/null +++ b/src/browser/components/sessionstore/SessionFile-sys-mjs.patch @@ -0,0 +1,21 @@ +diff --git a/browser/components/sessionstore/SessionFile.sys.mjs b/browser/components/sessionstore/SessionFile.sys.mjs +index 157c55ab24a418b56690d2e26320582909b919e4..14755f57dc450583e69eee94eb11f16980d5e5cb 100644 +--- a/browser/components/sessionstore/SessionFile.sys.mjs ++++ b/browser/components/sessionstore/SessionFile.sys.mjs +@@ -22,6 +22,7 @@ ChromeUtils.defineESModuleGetters(lazy, { + RunState: "resource:///modules/sessionstore/RunState.sys.mjs", + SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", + SessionWriter: "resource:///modules/sessionstore/SessionWriter.sys.mjs", ++ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", + }); + + const PREF_UPGRADE_BACKUP = "browser.sessionstore.upgradeBackup.latestBuildID"; +@@ -364,7 +365,7 @@ var SessionFileInternal = { + this._readOrigin = result.origin; + + result.noFilesFound = noFilesFound; +- ++ await lazy.ZenSessionStore.readFile(); + return result; + }, + diff --git a/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch new file mode 100644 index 000000000..b106193cf --- /dev/null +++ b/src/browser/components/sessionstore/SessionStartup-sys-mjs.patch @@ -0,0 +1,21 @@ +diff --git a/browser/components/sessionstore/SessionStartup.sys.mjs b/browser/components/sessionstore/SessionStartup.sys.mjs +index be23213ae9ec7e59358a17276c6c3764d38d9996..ca5a8ccc916ceeab5140f1278d15233cefbe5815 100644 +--- a/browser/components/sessionstore/SessionStartup.sys.mjs ++++ b/browser/components/sessionstore/SessionStartup.sys.mjs +@@ -40,6 +40,7 @@ ChromeUtils.defineESModuleGetters(lazy, { + StartupPerformance: + "resource:///modules/sessionstore/StartupPerformance.sys.mjs", + sessionStoreLogger: "resource:///modules/sessionstore/SessionLogger.sys.mjs", ++ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", + }); + + const STATE_RUNNING_STR = "running"; +@@ -179,6 +180,8 @@ export var SessionStartup = { + this._initialState = parsed; + } + ++ lazy.ZenSessionStore.onFileRead(this._initialState); ++ + if (this._initialState == null) { + // No valid session found. + this._sessionType = this.NO_SESSION; diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index 79c5bcfcf..66bcc8301 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d89fb95494 100644 +index eb62ff3e733e43fdaa299babddea3ba0125abb06..09567fe1be2af56429b60cbcbb36aa477fa68794 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -126,6 +126,8 @@ const TAB_EVENTS = [ @@ -11,7 +11,15 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 ]; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -@@ -1904,6 +1906,8 @@ var SessionStoreInternal = { +@@ -195,6 +197,7 @@ ChromeUtils.defineESModuleGetters(lazy, { + TabStateCache: "resource:///modules/sessionstore/TabStateCache.sys.mjs", + TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.sys.mjs", + setTimeout: "resource://gre/modules/Timer.sys.mjs", ++ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", + }); + + ChromeUtils.defineLazyGetter(lazy, "blankURI", () => { +@@ -1904,6 +1907,8 @@ var SessionStoreInternal = { case "TabPinned": case "TabUnpinned": case "SwapDocShells": @@ -20,7 +28,18 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2139,7 +2143,6 @@ var SessionStoreInternal = { +@@ -2041,6 +2046,10 @@ var SessionStoreInternal = { + // A regular window is not a private window, taskbar tab window, or popup window + let isRegularWindow = + !isPrivateWindow && !isTaskbarTab && aWindow.toolbar.visible; ++ if (!aInitialState && isRegularWindow) { ++ aInitialState = ZenSessionStore.getNewWindowData(this._windows); ++ this.restoreWindows(aWindow, aInitialState, {}); ++ } + + // perform additional initialization when the first window is loading + if (lazy.RunState.isStopped) { +@@ -2139,7 +2148,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -28,7 +47,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2372,11 +2375,9 @@ var SessionStoreInternal = { +@@ -2372,11 +2380,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } @@ -40,7 +59,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 // Store the window's close date to figure out when each individual tab // was closed. This timestamp should allow re-arranging data based on how -@@ -3361,7 +3362,7 @@ var SessionStoreInternal = { +@@ -3361,7 +3367,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -49,7 +68,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 return; } -@@ -4073,6 +4074,11 @@ var SessionStoreInternal = { +@@ -4073,6 +4079,11 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -61,7 +80,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4509,6 +4515,7 @@ var SessionStoreInternal = { +@@ -4509,6 +4520,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -69,7 +88,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5358,7 +5365,7 @@ var SessionStoreInternal = { +@@ -5358,7 +5370,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -78,7 +97,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 removableTabs.push(tab); } } -@@ -5418,7 +5425,7 @@ var SessionStoreInternal = { +@@ -5418,7 +5430,7 @@ var SessionStoreInternal = { } let workspaceID = aWindow.getWorkspaceID(); @@ -87,7 +106,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 winData.workspaceID = workspaceID; } }, -@@ -5609,11 +5616,12 @@ var SessionStoreInternal = { +@@ -5609,11 +5621,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -101,7 +120,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5624,6 +5632,7 @@ var SessionStoreInternal = { +@@ -5624,6 +5637,7 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -109,7 +128,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5636,7 +5645,7 @@ var SessionStoreInternal = { +@@ -5636,7 +5650,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -118,7 +137,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5748,8 +5757,8 @@ var SessionStoreInternal = { +@@ -5748,8 +5762,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -129,7 +148,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5792,6 +5801,8 @@ var SessionStoreInternal = { +@@ -5792,6 +5806,8 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -138,7 +157,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6348,6 +6359,25 @@ var SessionStoreInternal = { +@@ -6348,6 +6364,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -164,7 +183,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d8 if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7263,7 +7293,7 @@ var SessionStoreInternal = { +@@ -7263,7 +7298,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { diff --git a/src/zen/ZenComponents.manifest b/src/zen/ZenComponents.manifest new file mode 100644 index 000000000..46b75485e --- /dev/null +++ b/src/zen/ZenComponents.manifest @@ -0,0 +1,15 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# nsBrowserGlue.js + +# This component must restrict its registration for the app-startup category +# to the specific list of apps that use it so it doesn't get loaded in xpcshell. +# Thus we restrict it to these apps: +# +# browser: {ec8030f7-c20a-464f-9b0e-13a3a9e97384} + +category app-startup nsBrowserGlue @mozilla.org/browser/browserglue;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} + +#include sessionstore/SessionComponents.manifest diff --git a/src/zen/folders/ZenFolder.mjs b/src/zen/folders/ZenFolder.mjs index f6ac00a86..391425779 100644 --- a/src/zen/folders/ZenFolder.mjs +++ b/src/zen/folders/ZenFolder.mjs @@ -150,7 +150,6 @@ for (let tab of this.allItems.reverse()) { tab = tab.group.hasAttribute('split-view-group') ? tab.group : tab; if (tab.hasAttribute('zen-empty-tab')) { - await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id')); gBrowser.removeTab(tab); } else { gBrowser.ungroupTab(tab); @@ -160,7 +159,6 @@ async delete() { for (const tab of this.allItemsRecursive) { - await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id')); if (tab.hasAttribute('zen-empty-tab')) { // Manually remove the empty tabs as removeTabs() inside removeTabGroup // does ignore them. diff --git a/src/zen/moz.build b/src/zen/moz.build index 56782122f..eb681597f 100644 --- a/src/zen/moz.build +++ b/src/zen/moz.build @@ -2,6 +2,10 @@ # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. +EXTRA_PP_COMPONENTS += [ + "ZenComponents.manifest", +] + DIRS += [ "common", "glance", @@ -9,4 +13,5 @@ DIRS += [ "tests", "urlbar", "toolkit", + "sessionstore", ] diff --git a/src/zen/sessionstore/SessionComponents.manifest b/src/zen/sessionstore/SessionComponents.manifest new file mode 100644 index 000000000..f8f08d1d7 --- /dev/null +++ b/src/zen/sessionstore/SessionComponents.manifest @@ -0,0 +1,6 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +# Browser global components initializing before UI startup +category browser-before-ui-startup resource:///modules/zen/ZenSessionManager.sys.mjs ZenSessionStore.init diff --git a/src/zen/sessionstore/ZenSessionFile.sys.mjs b/src/zen/sessionstore/ZenSessionFile.sys.mjs index c50960ae1..526f7ab04 100644 --- a/src/zen/sessionstore/ZenSessionFile.sys.mjs +++ b/src/zen/sessionstore/ZenSessionFile.sys.mjs @@ -2,26 +2,39 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -const FILE_NAME = 'zen-sessions.jsonlz4'; +// Note that changing this hidden pref will make the previous session file +// unused, causing a new session file to be created on next write. +const SHOULD_COMPRESS_FILE = Services.prefs.getBoolPref('zen.session-store.compress-file', true); + +const FILE_NAME = SHOULD_COMPRESS_FILE ? 'zen-sessions.jsonlz4' : 'zen-sessions.json'; export class nsZenSessionFile { - #path; - - #windows; - - constructor() { - this.#path = PathUtils.join(profileDir, FILE_NAME); - } + #path = PathUtils.join(PathUtils.profileDir, FILE_NAME); + #sidebar = []; async read() { try { - return await IOUtils.readJSON(this.#path, { compress: true }); - } catch (e) { - return {}; + const data = await IOUtils.readJSON(this.#path, { compress: SHOULD_COMPRESS_FILE }); + this.#sidebar = data.sidebar || []; + } catch { + // File doesn't exist yet, that's fine. } } - async write(data) { - await IOUtils.writeJSON(this.#path, data, { compress: true }); + get sidebar() { + return this.#sidebar; + } + + set sidebar(data) { + this.#sidebar = data; + } + + async #write(data) { + await IOUtils.writeJSON(this.#path, data, { compress: SHOULD_COMPRESS_FILE }); + } + + async store() { + const data = { sidebar: this.#sidebar }; + await this.#write(data); } } diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 68aa829e4..5120319bc 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -12,23 +12,74 @@ import { const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { - ZenSessionFile: 'resource://gre/modules/ZenSessionFile.sys.mjs', + nsZenSessionFile: 'resource:///modules/zen/ZenSessionFile.sys.mjs', PrivateBrowsingUtils: 'resource://gre/modules/PrivateBrowsingUtils.sys.mjs', - RunState: 'resource:///modules/sessionstore/RunState.sys.mjs', + BrowserWindowTracker: 'resource:///modules/BrowserWindowTracker.sys.mjs', + TabGroupState: 'resource:///modules/sessionstore/TabGroupState.sys.mjs', + SessionStore: 'resource:///modules/sessionstore/SessionStore.sys.mjs', }); +const TAB_CUSTOM_VALUES = new WeakMap(); +const LAZY_COLLECT_THRESHOLD = 5 * 60 * 1000; // 5 minutes +const OBSERVING = ['sessionstore-state-write-complete', 'browser-window-before-show']; + class nsZenSessionManager { #file; constructor() { - this.#file = null; + this.#file = new lazy.nsZenSessionFile(); } - get file() { - if (!this.#file) { - this.#file = lazy.ZenSessionFile; + // Called from SessionComponents.manifest on app-startup + init() { + this.#initObservers(); + } + + async readFile() { + await this.#file.read(); + } + + onFileRead(initialState) { + for (const winData of initialState.windows || []) { + this.restoreWindowData(winData); } - return this.#file; + } + + #initObservers() { + for (let topic of OBSERVING) { + Services.obs.addObserver(this, topic); + } + } + + get #sidebar() { + return this.#file.sidebar; + } + + set #sidebar(data) { + this.#file.sidebar = data; + } + + observe(aSubject, aTopic) { + switch (aTopic) { + case 'sessionstore-state-write-complete': { + this.#saveState(true); + break; + } + case 'browser-window-before-show': // catch new windows + this.#onBeforeBrowserWindowShown(aSubject); + break; + default: + break; + } + } + + /** Handles the browser-window-before-show observer notification. */ + #onBeforeBrowserWindowShown(aWindow) { + // TODO: Initialize new window + } + + get #topMostWindow() { + return lazy.BrowserWindowTracker.getTopWindow(); } /** @@ -38,12 +89,82 @@ class nsZenSessionManager { * Forces us to recollect data for all windows and will bypass and * update the corresponding caches. */ - saveState(forceUpdateAllWindows = false) { + async #saveState(forceUpdateAllWindows = false) { if (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) { // Don't save (or even collect) anything in permanent private // browsing mode return Promise.resolve(); } + // Collect an initial snapshot of window data before we do the flush. + const window = this.#topMostWindow; + // We don't have any normal windows or no windows at all + if (!window) { + return; + } + this.#collectWindowData(this.#topMostWindow, forceUpdateAllWindows); + this.#file.store(); + } + + /** + * Collects session data for a given window. + * + * @param window + * The window to collect data for. + * @param forceUpdate + * Forces us to recollect data and will bypass and update the + * corresponding caches. + * @param zIndex + * The z-index of the window. + */ + #collectWindowData(window, forceUpdate = false, zIndex = 0) { + let sidebarData = this.#sidebar; + if (!sidebarData || forceUpdate) { + sidebarData = {}; + } + + // If it hasn't changed, don't update. + if ( + !forceUpdate && + sidebarData.lastCollected && + Date.now() - sidebarData.lastCollected < LAZY_COLLECT_THRESHOLD + ) { + return; + } + sidebarData.lastCollected = Date.now(); + this.#collectTabsData(window, sidebarData); + this.#sidebar = sidebarData; + } + + /** + * Collects session data for all tabs in a given window. + * + * @param aWindow + * The window to collect tab data for. + * @param winData + * The window data object to populate. + */ + #collectTabsData(aWindow, sidebarData) { + const winData = lazy.SessionStore.getWindowState(aWindow).windows[0]; + if (!winData) return; + sidebarData.tabs = winData.tabs; + sidebarData.folders = winData.folders; + sidebarData.splitViewData = winData.splitViewData; + sidebarData.groups = winData.groups; + } + + restoreWindowData(aWindowData) { + const sidebar = this.#file.sidebar; + if (!sidebar) { + return; + } + aWindowData.tabs = sidebar.tabs || []; + aWindowData.splitViewData = sidebar.splitViewData; + aWindowData.folders = sidebar.folders; + aWindowData.groups = sidebar.groups; + } + + getNewWindowData(aWindows) { + return { windows: [Cu.cloneInto(aWindows[Object.keys(aWindows)[0]], {})] }; } } diff --git a/src/zen/sessionstore/ZenSessionWindow.sys.mjs b/src/zen/sessionstore/ZenSessionWindow.sys.mjs deleted file mode 100644 index 460070234..000000000 --- a/src/zen/sessionstore/ZenSessionWindow.sys.mjs +++ /dev/null @@ -1,35 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. - -export class ZenSessionWindow { - #id; - #selectedWorkspace; - #selectedTab; - - constructor(id) { - this.#id = id; - this.#selectedWorkspace = null; - this.#selectedTab = null; - } - - get id() { - return this.#id; - } - - get selectedWorkspace() { - return this.#selectedWorkspace; - } - - set selectedWorkspace(workspace) { - this.#selectedWorkspace = workspace; - } - - get selectedTab() { - return this.#selectedTab; - } - - set selectedTab(tab) { - this.#selectedTab = tab; - } -} diff --git a/src/zen/sessionstore/moz.build b/src/zen/sessionstore/moz.build new file mode 100644 index 000000000..af5a7dd3b --- /dev/null +++ b/src/zen/sessionstore/moz.build @@ -0,0 +1,8 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +EXTRA_JS_MODULES.zen += [ + "ZenSessionFile.sys.mjs", + "ZenSessionManager.sys.mjs", +] diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index 58992f4ca..19586d3f7 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -211,197 +211,7 @@ } async #initializePinnedTabs(init = false) { - const pins = this._pinsCache; - if (!pins?.length || !init) { - this.#finishedInitializingPins(); - return; - } - - const pinnedTabsByUUID = new Map(); - const pinsToCreate = new Set(pins.map((p) => p.uuid)); - - // First pass: identify existing tabs and remove those without pins - for (let tab of gZenWorkspaces.allStoredTabs) { - const pinId = tab.getAttribute('zen-pin-id'); - if (!pinId) { - continue; - } - - if (pinsToCreate.has(pinId)) { - // This is a valid pinned tab that matches a pin - pinnedTabsByUUID.set(pinId, tab); - pinsToCreate.delete(pinId); - - if (lazy.zenPinnedTabRestorePinnedTabsToPinnedUrl && init) { - this._resetTabToStoredState(tab); - } - } else { - // This is a pinned tab that no longer has a corresponding pin - gBrowser.removeTab(tab); - } - } - - for (const group of gZenWorkspaces.allTabGroups) { - const pinId = group.getAttribute('zen-pin-id'); - if (!pinId) { - continue; - } - if (pinsToCreate.has(pinId)) { - // This is a valid pinned group that matches a pin - pinsToCreate.delete(pinId); - } - } - - // Second pass: For every existing tab, update its label - // and set 'zen-has-static-label' attribute if it's been edited - for (let pin of pins) { - const tab = pinnedTabsByUUID.get(pin.uuid); - if (!tab) { - continue; - } - - tab.removeAttribute('zen-has-static-label'); // So we can set it again - if (pin.title && pin.editedTitle) { - gBrowser._setTabLabel(tab, pin.title, { beforeTabOpen: true }); - tab.setAttribute('zen-has-static-label', 'true'); - } - } - - const groups = new Map(); - const pendingTabsInsideGroups = {}; - - // Third pass: create new tabs for pins that don't have tabs - for (let pin of pins) { - try { - if (!pinsToCreate.has(pin.uuid)) { - continue; // Skip pins that already have tabs - } - - if (pin.isGroup) { - const tabs = []; - // If there's already existing tabs, let's use them - for (const [uuid, existingTab] of pinnedTabsByUUID) { - const pinObject = this._pinsCache.find((p) => p.uuid === uuid); - if (pinObject && pinObject.parentUuid === pin.uuid) { - tabs.push(existingTab); - } - } - // We still need to iterate through pending tabs since the database - // query doesn't guarantee the order of insertion - for (const [parentUuid, folderTabs] of Object.entries(pendingTabsInsideGroups)) { - if (parentUuid === pin.uuid) { - tabs.push(...folderTabs); - } - } - const group = gZenFolders.createFolder(tabs, { - label: pin.title, - collapsed: pin.isFolderCollapsed, - initialPinId: pin.uuid, - workspaceId: pin.workspaceUuid, - insertAfter: - groups.get(pin.parentUuid)?.querySelector('.tab-group-container')?.lastChild || - null, - }); - gZenFolders.setFolderUserIcon(group, pin.folderIcon); - groups.set(pin.uuid, group); - continue; - } - - let params = { - skipAnimation: true, - allowInheritPrincipal: false, - skipBackgroundNotify: true, - userContextId: pin.containerTabId || 0, - createLazyBrowser: true, - skipLoad: true, - noInitialLabel: false, - }; - - // Create and initialize the tab - let newTab = gBrowser.addTrustedTab(pin.url, params); - newTab.setAttribute('zenDefaultUserContextId', true); - - // Set initial label/title - if (pin.title) { - gBrowser.setInitialTabTitle(newTab, pin.title); - } - - // Set the icon if we have it cached - if (pin.iconUrl) { - gBrowser.setIcon(newTab, pin.iconUrl); - } - - newTab.setAttribute('zen-pin-id', pin.uuid); - - if (pin.workspaceUuid) { - newTab.setAttribute('zen-workspace-id', pin.workspaceUuid); - } - - if (pin.isEssential) { - newTab.setAttribute('zen-essential', 'true'); - } - - if (pin.editedTitle) { - newTab.setAttribute('zen-has-static-label', 'true'); - } - - // Initialize browser state if needed - if (!newTab.linkedBrowser._remoteAutoRemoved) { - let state = { - entries: [ - { - url: pin.url, - title: pin.title, - triggeringPrincipal_base64: E10SUtils.SERIALIZED_SYSTEMPRINCIPAL, - }, - ], - userContextId: pin.containerTabId || 0, - image: pin.iconUrl, - }; - - SessionStore.setTabState(newTab, state); - } - - this.log(`Created new pinned tab for pin ${pin.uuid} (isEssential: ${pin.isEssential})`); - gBrowser.pinTab(newTab); - - if (pin.parentUuid) { - const parentGroup = groups.get(pin.parentUuid); - if (parentGroup) { - parentGroup.querySelector('.tab-group-container').appendChild(newTab); - } else { - if (pendingTabsInsideGroups[pin.parentUuid]) { - pendingTabsInsideGroups[pin.parentUuid].push(newTab); - } else { - pendingTabsInsideGroups[pin.parentUuid] = [newTab]; - } - } - } else { - if (!pin.isEssential) { - const container = gZenWorkspaces.workspaceElement( - pin.workspaceUuid - )?.pinnedTabsContainer; - if (container) { - container.insertBefore(newTab, container.lastChild); - } - } else { - gZenWorkspaces.getEssentialsSection(pin.containerTabId).appendChild(newTab); - } - } - - gBrowser.tabContainer._invalidateCachedTabs(); - newTab.initialize(); - } catch (ex) { - console.error('Failed to initialize pinned tabs:', ex); - } - } - - setTimeout(() => { - this.#finishedInitializingPins(); - }, 0); - - gBrowser._updateTabBarForPinnedTabs(); - gZenUIManager.updateTabsToolbar(); + this.#finishedInitializingPins(); } _onPinnedTabEvent(action, event) { diff --git a/src/zen/zen.globals.js b/src/zen/zen.globals.js index a225ca767..ca472fc1e 100644 --- a/src/zen/zen.globals.js +++ b/src/zen/zen.globals.js @@ -27,7 +27,6 @@ export default [ 'ZenWorkspaceBookmarksStorage', 'gZenPinnedTabManager', - 'ZenPinnedTabsStorage', 'gZenEmojiPicker', 'gZenSessionStore', From 76acc8b0e41e43fab2a1509825be91573be540b7 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Fri, 31 Oct 2025 23:07:38 +0100 Subject: [PATCH 08/18] feat: Stop using pinned manager and use zen session sidebar, b=no-bug, c=common, folders, tabs, workspaces --- src/browser/base/content/zen-assets.inc.xhtml | 1 - .../base/content/zen-assets.jar.inc.mn | 1 - .../sessionstore/SessionStore-sys-mjs.patch | 8 +- .../sessionstore/TabState-sys-mjs.patch | 4 +- .../tabbrowser/content/tab-js.patch | 8 - .../tabbrowser/content/tabbrowser-js.patch | 18 - src/zen/common/ZenSessionStore.mjs | 4 +- src/zen/common/ZenUIManager.mjs | 8 - src/zen/folders/ZenFolders.mjs | 19 +- .../sessionstore/ZenSessionManager.sys.mjs | 16 +- src/zen/tabs/ZenPinnedTabManager.mjs | 430 +----------- src/zen/tabs/ZenPinnedTabsStorage.mjs | 635 ------------------ src/zen/workspaces/ZenWindowSyncing.mjs | 8 +- src/zen/workspaces/ZenWorkspaces.mjs | 6 - 14 files changed, 28 insertions(+), 1138 deletions(-) delete mode 100644 src/zen/tabs/ZenPinnedTabsStorage.mjs diff --git a/src/browser/base/content/zen-assets.inc.xhtml b/src/browser/base/content/zen-assets.inc.xhtml index 0ae64eab2..a61105b51 100644 --- a/src/browser/base/content/zen-assets.inc.xhtml +++ b/src/browser/base/content/zen-assets.inc.xhtml @@ -48,7 +48,6 @@ - diff --git a/src/browser/base/content/zen-assets.jar.inc.mn b/src/browser/base/content/zen-assets.jar.inc.mn index 8825284ba..efee1ce48 100644 --- a/src/browser/base/content/zen-assets.jar.inc.mn +++ b/src/browser/base/content/zen-assets.jar.inc.mn @@ -51,7 +51,6 @@ content/browser/zen-components/ZenKeyboardShortcuts.mjs (../../zen/kbs/ZenKeyboardShortcuts.mjs) - content/browser/zen-components/ZenPinnedTabsStorage.mjs (../../zen/tabs/ZenPinnedTabsStorage.mjs) content/browser/zen-components/ZenPinnedTabManager.mjs (../../zen/tabs/ZenPinnedTabManager.mjs) * content/browser/zen-styles/zen-tabs.css (../../zen/tabs/zen-tabs.css) content/browser/zen-styles/zen-tabs/vertical-tabs.css (../../zen/tabs/zen-tabs/vertical-tabs.css) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index 66bcc8301..ef89b7892 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index eb62ff3e733e43fdaa299babddea3ba0125abb06..09567fe1be2af56429b60cbcbb36aa477fa68794 100644 +index eb62ff3e733e43fdaa299babddea3ba0125abb06..1ca2e7327e72824805a93c18cb7e3dfd499c66d7 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -126,6 +126,8 @@ const TAB_EVENTS = [ @@ -33,7 +33,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..09567fe1be2af56429b60cbcbb36aa47 let isRegularWindow = !isPrivateWindow && !isTaskbarTab && aWindow.toolbar.visible; + if (!aInitialState && isRegularWindow) { -+ aInitialState = ZenSessionStore.getNewWindowData(this._windows); ++ aInitialState = lazy.ZenSessionStore.getNewWindowData(this._windows); + this.restoreWindows(aWindow, aInitialState, {}); + } @@ -171,8 +171,8 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..09567fe1be2af56429b60cbcbb36aa47 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenPinnedId) { -+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId); ++ if (tabData.zenSyncId) { ++ tab.setAttribute("zen-sync-id", tabData.zenSyncId); + } + if (tabData.zenDefaultUserContextId) { + tab.setAttribute("zenDefaultUserContextId", true); diff --git a/src/browser/components/sessionstore/TabState-sys-mjs.patch b/src/browser/components/sessionstore/TabState-sys-mjs.patch index 2100e2334..cfeea5035 100644 --- a/src/browser/components/sessionstore/TabState-sys-mjs.patch +++ b/src/browser/components/sessionstore/TabState-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/TabState.sys.mjs b/browser/components/sessionstore/TabState.sys.mjs -index 82721356d191055bec0d4b0ca49e481221988801..1ea5c394c704da295149443d7794961a12f2060b 100644 +index 82721356d191055bec0d4b0ca49e481221988801..d1323fe17c995611ebdfe2869b0ccd2d45bcfa11 100644 --- a/browser/components/sessionstore/TabState.sys.mjs +++ b/browser/components/sessionstore/TabState.sys.mjs @@ -85,7 +85,22 @@ class _TabState { @@ -7,7 +7,7 @@ index 82721356d191055bec0d4b0ca49e481221988801..1ea5c394c704da295149443d7794961a } + tabData.zenWorkspace = tab.getAttribute("zen-workspace-id"); -+ tabData.zenPinnedId = tab.getAttribute("zen-pin-id"); ++ tabData.zenSyncId = tab.getAttribute("zen-sync-id"); + tabData.zenEssential = tab.getAttribute("zen-essential"); + tabData.pinned = tabData.pinned || tabData.zenEssential; + tabData.zenDefaultUserContextId = tab.getAttribute("zenDefaultUserContextId"); diff --git a/src/browser/components/tabbrowser/content/tab-js.patch b/src/browser/components/tabbrowser/content/tab-js.patch index 997098854..f9f19d12d 100644 --- a/src/browser/components/tabbrowser/content/tab-js.patch +++ b/src/browser/components/tabbrowser/content/tab-js.patch @@ -121,14 +121,6 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef on_click(event) { if (event.button != 0) { return; -@@ -570,6 +592,7 @@ - ) - ); - } else { -+ gZenPinnedTabManager._removePinnedAttributes(this, true); - gBrowser.removeTab(this, { - animate: true, - triggeringEvent: event, @@ -582,6 +605,14 @@ // (see tabbrowser-tabs 'click' handler). gBrowser.tabContainer._blockDblClick = true; diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index 11561149a..ccccb80c7 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -477,16 +477,6 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 TabBarVisibility.update(); } -@@ -4553,6 +4680,9 @@ - return; - } - -+ for (let tab of selectedTabs) { -+ gZenPinnedTabManager._removePinnedAttributes(tab, true); -+ } - this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource }); - } - @@ -4814,6 +4944,7 @@ telemetrySource, } = {} @@ -838,11 +828,3 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // Build Ask Chat items TabContextMenu.GenAI.buildTabMenu( document.getElementById("context_askChat"), -@@ -9763,6 +9944,7 @@ var TabContextMenu = { - ) - ); - } else { -+ gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true); - gBrowser.removeTab(this.contextTab, { - animate: true, - ...gBrowser.TabMetrics.userTriggeredContext( diff --git a/src/zen/common/ZenSessionStore.mjs b/src/zen/common/ZenSessionStore.mjs index 2b86d886e..3ad0e706b 100644 --- a/src/zen/common/ZenSessionStore.mjs +++ b/src/zen/common/ZenSessionStore.mjs @@ -15,8 +15,8 @@ if (tabData.zenWorkspace) { tab.setAttribute('zen-workspace-id', tabData.zenWorkspace); } - if (tabData.zenPinnedId) { - tab.setAttribute('zen-pin-id', tabData.zenPinnedId); + if (tabData.zenSyncId) { + tab.setAttribute('zen-sync-id', tabData.zenSyncId); } if (tabData.zenHasStaticLabel) { tab.setAttribute('zen-has-static-label', 'true'); diff --git a/src/zen/common/ZenUIManager.mjs b/src/zen/common/ZenUIManager.mjs index a95f7e60d..d597c463d 100644 --- a/src/zen/common/ZenUIManager.mjs +++ b/src/zen/common/ZenUIManager.mjs @@ -1249,14 +1249,6 @@ var gZenVerticalTabsManager = { } else { gBrowser.setTabTitle(this._tabEdited); } - if (this._tabEdited.getAttribute('zen-pin-id')) { - // Update pin title in storage - await gZenPinnedTabManager.updatePinTitle( - this._tabEdited, - this._tabEdited.label, - !!newName - ); - } // Maybe add some confetti here?!? gZenUIManager.motion.animate( diff --git a/src/zen/folders/ZenFolders.mjs b/src/zen/folders/ZenFolders.mjs index 3d181132b..c2b328378 100644 --- a/src/zen/folders/ZenFolders.mjs +++ b/src/zen/folders/ZenFolders.mjs @@ -508,9 +508,6 @@ tabs = [emptyTab, ...filteredTabs]; const folder = this._createFolderNode(options); - if (options.initialPinId) { - folder.setAttribute('zen-pin-id', options.initialPinId); - } if (options.insertAfter) { options.insertAfter.after(folder); @@ -940,7 +937,7 @@ if (!parentFolder && folder.hasAttribute('split-view-group')) continue; const emptyFolderTabs = folder.tabs .filter((tab) => tab.hasAttribute('zen-empty-tab')) - .map((tab) => tab.getAttribute('zen-pin-id')); + .map((tab) => tab.getAttribute('zen-sync-id')); let prevSiblingInfo = null; const prevSibling = folder.previousElementSibling; @@ -949,8 +946,8 @@ if (prevSibling) { if (gBrowser.isTabGroup(prevSibling)) { prevSiblingInfo = { type: 'group', id: prevSibling.id }; - } else if (gBrowser.isTab(prevSibling) && prevSibling.hasAttribute('zen-pin-id')) { - const zenPinId = prevSibling.getAttribute('zen-pin-id'); + } else if (gBrowser.isTab(prevSibling) && prevSibling.hasAttribute('zen-sync-id')) { + const zenPinId = prevSibling.getAttribute('zen-sync-id'); prevSiblingInfo = { type: 'tab', id: zenPinId }; } else { prevSiblingInfo = { type: 'start', id: null }; @@ -969,7 +966,7 @@ prevSiblingInfo: prevSiblingInfo, emptyTabIds: emptyFolderTabs, userIcon: userIcon?.getAttribute('href'), - pinId: folder.getAttribute('zen-pin-id'), + syncId: folder.getAttribute('zen-sync-id'), // note: We shouldn't be using the workspace-id anywhere, we are just // remembering it for the pinned tabs manager to use it later. workspaceId: folder.getAttribute('zen-workspace-id'), @@ -996,9 +993,9 @@ tabFolderWorkingData.set(folderData.id, workingData); const oldGroup = document.getElementById(folderData.id); - folderData.emptyTabIds.forEach((zenPinId) => { + folderData.emptyTabIds.forEach((zenSyncId) => { oldGroup - ?.querySelector(`tab[zen-pin-id="${zenPinId}"]`) + ?.querySelector(`tab[zen-sync-id="${zenSyncId}"]`) ?.setAttribute('zen-empty-tab', true); }); if (oldGroup) { @@ -1011,7 +1008,7 @@ saveOnWindowClose: folderData.saveOnWindowClose, workspaceId: folderData.workspaceId, }); - folder.setAttribute('zen-pin-id', folderData.pinId); + folder.setAttribute('zen-sync-id', folderData.syncId); workingData.node = folder; oldGroup.before(folder); } else { @@ -1044,7 +1041,7 @@ switch (stateData?.prevSiblingInfo?.type) { case 'tab': { const tab = parentWorkingData.node.querySelector( - `[zen-pin-id="${stateData.prevSiblingInfo.id}"]` + `[zen-sync-id="${stateData.prevSiblingInfo.id}"]` ); tab.after(node); break; diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 5120319bc..e8cf59114 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -2,13 +2,6 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. -import { - cancelIdleCallback, - clearTimeout, - requestIdleCallback, - setTimeout, -} from 'resource://gre/modules/Timer.sys.mjs'; - const lazy = {}; ChromeUtils.defineESModuleGetters(lazy, { @@ -19,7 +12,6 @@ ChromeUtils.defineESModuleGetters(lazy, { SessionStore: 'resource:///modules/sessionstore/SessionStore.sys.mjs', }); -const TAB_CUSTOM_VALUES = new WeakMap(); const LAZY_COLLECT_THRESHOLD = 5 * 60 * 1000; // 5 minutes const OBSERVING = ['sessionstore-state-write-complete', 'browser-window-before-show']; @@ -76,6 +68,7 @@ class nsZenSessionManager { /** Handles the browser-window-before-show observer notification. */ #onBeforeBrowserWindowShown(aWindow) { // TODO: Initialize new window + void aWindow; } get #topMostWindow() { @@ -113,10 +106,8 @@ class nsZenSessionManager { * @param forceUpdate * Forces us to recollect data and will bypass and update the * corresponding caches. - * @param zIndex - * The z-index of the window. */ - #collectWindowData(window, forceUpdate = false, zIndex = 0) { + #collectWindowData(window, forceUpdate = false) { let sidebarData = this.#sidebar; if (!sidebarData || forceUpdate) { sidebarData = {}; @@ -164,7 +155,8 @@ class nsZenSessionManager { } getNewWindowData(aWindows) { - return { windows: [Cu.cloneInto(aWindows[Object.keys(aWindows)[0]], {})] }; + let newWindow = { ...Cu.cloneInto(aWindows[Object.keys(aWindows)[0]], {}), ...this.#sidebar }; + return { windows: [newWindow] }; } } diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index e555a3346..245819a91 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -5,23 +5,7 @@ const lazy = {}; class ZenPinnedTabsObserver { - static ALL_EVENTS = [ - 'TabPinned', - 'TabUnpinned', - 'TabMove', - 'TabGroupCreate', - 'TabGroupRemoved', - 'TabGroupMoved', - 'ZenFolderRenamed', - 'ZenFolderIconChanged', - 'TabGroupCollapse', - 'TabGroupExpand', - 'TabGrouped', - 'TabUngrouped', - 'ZenFolderChangedWorkspace', - 'TabAddedToEssentials', - 'TabRemovedFromEssentials', - ]; + static ALL_EVENTS = ['TabPinned', 'TabUnpinned']; #listeners = []; @@ -103,21 +87,8 @@ onTabIconChanged(tab, url = null) { tab.dispatchEvent(new CustomEvent('ZenTabIconChanged', { bubbles: true, detail: { tab } })); const iconUrl = url ?? tab.iconImage.src; - if (!iconUrl && tab.hasAttribute('zen-pin-id')) { - try { - setTimeout(async () => { - const favicon = await this.getFaviconAsBase64(tab.linkedBrowser.currentURI); - if (favicon) { - gBrowser.setIcon(tab, favicon); - } - }); - } catch { - // Handle error - } - } else { - if (tab.hasAttribute('zen-essential')) { - tab.style.setProperty('--zen-essential-tab-icon', `url(${iconUrl})`); - } + if (tab.hasAttribute('zen-essential')) { + tab.style.setProperty('--zen-essential-tab-icon', `url(${iconUrl})`); } } @@ -149,71 +120,6 @@ return lazy.zenTabsEssentialsMax; } - async refreshPinnedTabs({ init = false } = {}) { - if (!this.enabled) { - return; - } - await ZenPinnedTabsStorage.promiseInitialized; - await this.#initializePinsCache(); - setTimeout(async () => { - // Execute in a separate task to avoid blocking the main thread - await SessionStore.promiseAllWindowsRestored; - await gZenWorkspaces.promiseInitialized; - await this.#initializePinnedTabs(init); - if (init) { - this._hasFinishedLoading = true; - } - }, 10); - } - - async #initializePinsCache() { - try { - // Get pin data - const pins = await ZenPinnedTabsStorage.getPins(); - - // Enhance pins with favicons - this._pinsCache = await Promise.all( - pins.map(async (pin) => { - try { - if (pin.isGroup) { - return pin; // Skip groups for now - } - const image = await this.getFaviconAsBase64(Services.io.newURI(pin.url)); - return { - ...pin, - iconUrl: image || null, - }; - } catch { - // If favicon fetch fails, continue without icon - return { - ...pin, - iconUrl: null, - }; - } - }) - ); - } catch (ex) { - console.error('Failed to initialize pins cache:', ex); - this._pinsCache = []; - } - - this.log(`Initialized pins cache with ${this._pinsCache.length} pins`); - return this._pinsCache; - } - - #finishedInitializingPins() { - if (this.hasInitializedPins) { - return; - } - this._resolvePinnedInitializedInternal(); - delete this._resolvePinnedInitializedInternal; - this.hasInitializedPins = true; - } - - async #initializePinnedTabs(init = false) { - this.#finishedInitializingPins(); - } - _onPinnedTabEvent(action, event) { if (!this.enabled) return; const tab = event.target; @@ -223,230 +129,22 @@ } switch (action) { case 'TabPinned': - case 'TabAddedToEssentials': tab._zenClickEventListener = this._zenClickEventListener; tab.addEventListener('click', tab._zenClickEventListener); - this._setPinnedAttributes(tab); break; - case 'TabRemovedFromEssentials': - if (tab.pinned) { - this.#onTabMove(tab); - break; - } // [Fall through] case 'TabUnpinned': - this._removePinnedAttributes(tab); if (tab._zenClickEventListener) { tab.removeEventListener('click', tab._zenClickEventListener); delete tab._zenClickEventListener; } break; - case 'TabMove': - this.#onTabMove(tab); - break; - case 'TabGroupCreate': - this.#onTabGroupCreate(event); - break; - case 'TabGroupRemoved': - this.#onTabGroupRemoved(event); - break; - case 'TabGroupMoved': - this.#onTabGroupMoved(event); - break; - case 'ZenFolderRenamed': - case 'ZenFolderIconChanged': - case 'TabGroupCollapse': - case 'TabGroupExpand': - case 'ZenFolderChangedWorkspace': - this.#updateGroupInfo(event.originalTarget); - break; - case 'TabGrouped': - this.#onTabGrouped(event); - break; - case 'TabUngrouped': - this.#onTabUngrouped(event); - break; default: console.warn('ZenPinnedTabManager: Unhandled tab event', action); break; } } - async #onTabGroupCreate(event) { - const group = event.originalTarget; - if (!group.isZenFolder) { - return; - } - if (group.hasAttribute('zen-pin-id')) { - return; // Group already exists in storage - } - const workspaceId = group.getAttribute('zen-workspace-id'); - let id = await ZenPinnedTabsStorage.createGroup( - group.name, - group.iconURL, - group.collapsed, - workspaceId, - group.getAttribute('zen-pin-id'), - group._pPos - ); - group.setAttribute('zen-pin-id', id); - for (const tab of group.tabs) { - // Only add it if the tab is directly under the group - if ( - tab.pinned && - tab.hasAttribute('zen-pin-id') && - tab.group === group && - this.hasInitializedPins - ) { - const tabPinId = tab.getAttribute('zen-pin-id'); - await ZenPinnedTabsStorage.addTabToGroup(tabPinId, id, /* position */ tab._pPos); - } - } - await this.refreshPinnedTabs(); - } - - async #onTabGrouped(event) { - const tab = event.detail; - const group = tab.group; - if (!group.isZenFolder) { - return; - } - const pinId = group.getAttribute('zen-pin-id'); - const tabPinId = tab.getAttribute('zen-pin-id'); - const tabPin = this._pinsCache?.find((p) => p.uuid === tabPinId); - if (!tabPin || !tabPin.group) { - return; - } - ZenPinnedTabsStorage.addTabToGroup(tabPinId, pinId, /* position */ tab._pPos); - } - - async #onTabUngrouped(event) { - const tab = event.detail; - const group = tab.group; - if (!group?.isZenFolder) { - return; - } - const tabPinId = tab.getAttribute('zen-pin-id'); - const tabPin = this._pinsCache?.find((p) => p.uuid === tabPinId); - if (!tabPin) { - return; - } - ZenPinnedTabsStorage.removeTabFromGroup(tabPinId, /* position */ tab._pPos); - } - - async #updateGroupInfo(group) { - if (!group?.isZenFolder) { - return; - } - const pinId = group.getAttribute('zen-pin-id'); - const groupPin = this._pinsCache?.find((p) => p.uuid === pinId); - if (groupPin) { - groupPin.title = group.name; - groupPin.folderIcon = group.iconURL; - groupPin.isFolderCollapsed = group.collapsed; - groupPin.position = group._pPos; - groupPin.parentUuid = group.group?.getAttribute('zen-pin-id') || null; - groupPin.workspaceUuid = group.getAttribute('zen-workspace-id') || null; - await this.savePin(groupPin); - for (const item of group.allItems) { - if (gBrowser.isTabGroup(item)) { - await this.#updateGroupInfo(item); - } else { - await this.#onTabMove(item); - } - } - } - } - - async #onTabGroupRemoved(event) { - const group = event.originalTarget; - if (!group.isZenFolder) { - return; - } - await ZenPinnedTabsStorage.removePin(group.getAttribute('zen-pin-id')); - group.removeAttribute('zen-pin-id'); - } - - async #onTabGroupMoved(event) { - const group = event.originalTarget; - if (!group.isZenFolder) { - return; - } - const newIndex = group._pPos; - const pinId = group.getAttribute('zen-pin-id'); - if (!pinId) { - return; - } - for (const tab of group.allItemsRecursive) { - if (tab.pinned && tab.getAttribute('zen-pin-id') === pinId) { - const pin = this._pinsCache.find((p) => p.uuid === pinId); - if (pin) { - pin.position = tab._pPos; - pin.parentUuid = tab.group?.getAttribute('zen-pin-id') || null; - pin.workspaceUuid = group.getAttribute('zen-workspace-id'); - await this.savePin(pin, false); - } - break; - } - } - const groupPin = this._pinsCache?.find((p) => p.uuid === pinId); - if (groupPin) { - groupPin.position = newIndex; - groupPin.parentUuid = group.group?.getAttribute('zen-pin-id'); - groupPin.workspaceUuid = group.getAttribute('zen-workspace-id'); - await this.savePin(groupPin); - } - } - - async #onTabMove(tab) { - if (!tab.pinned || !this._pinsCache) { - return; - } - - const allTabs = [...gBrowser.tabs, ...gBrowser.tabGroups]; - for (let i = 0; i < allTabs.length; i++) { - const otherTab = allTabs[i]; - if ( - otherTab.pinned && - otherTab.getAttribute('zen-pin-id') !== tab.getAttribute('zen-pin-id') - ) { - const actualPin = this._pinsCache.find( - (pin) => pin.uuid === otherTab.getAttribute('zen-pin-id') - ); - if (!actualPin) { - continue; - } - actualPin.position = otherTab._pPos; - actualPin.workspaceUuid = otherTab.getAttribute('zen-workspace-id'); - actualPin.parentUuid = otherTab.group?.getAttribute('zen-pin-id') || null; - await this.savePin(actualPin, false); - } - } - - const actualPin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id')); - - if (!actualPin) { - return; - } - actualPin.position = tab._pPos; - actualPin.isEssential = tab.hasAttribute('zen-essential'); - actualPin.parentUuid = tab.group?.getAttribute('zen-pin-id') || null; - actualPin.workspaceUuid = tab.getAttribute('zen-workspace-id') || null; - - // There was a bug where the title and hasStaticLabel attribute were not being set - // This is a workaround to fix that - if (tab.hasAttribute('zen-has-static-label')) { - actualPin.editedTitle = true; - actualPin.title = tab.label; - } - await this.savePin(actualPin); - tab.dispatchEvent( - new CustomEvent('ZenPinnedTabMoved', { - detail: { tab }, - }) - ); - } - async _onTabClick(e) { const tab = e.target?.closest('tab'); if (e.button === 1 && tab) { @@ -476,106 +174,10 @@ return; } - const browser = tab.linkedBrowser; - - const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id')); - - if (!pin) { - return; - } - - const userContextId = tab.getAttribute('usercontextid'); - - pin.title = tab.label || browser.contentTitle; - pin.url = browser.currentURI.spec; - pin.workspaceUuid = tab.getAttribute('zen-workspace-id'); - pin.userContextId = userContextId ? parseInt(userContextId, 10) : 0; - - await this.savePin(pin); this.resetPinChangedUrl(tab); - await this.refreshPinnedTabs(); gZenUIManager.showToast('zen-pinned-tab-replaced'); } - async _setPinnedAttributes(tab) { - if ( - tab.hasAttribute('zen-pin-id') || - !this._hasFinishedLoading || - tab.hasAttribute('zen-empty-tab') - ) { - return; - } - - this.log(`Setting pinned attributes for tab ${tab.linkedBrowser.currentURI.spec}`); - const browser = tab.linkedBrowser; - - const uuid = gZenUIManager.generateUuidv4(); - const userContextId = tab.getAttribute('usercontextid'); - - let entry = null; - - if (tab.getAttribute('zen-pinned-entry')) { - entry = JSON.parse(tab.getAttribute('zen-pinned-entry')); - } - - await this.savePin({ - uuid, - title: entry?.title || tab.label || browser.contentTitle, - url: entry?.url || browser.currentURI.spec, - containerTabId: userContextId ? parseInt(userContextId, 10) : 0, - workspaceUuid: tab.getAttribute('zen-workspace-id'), - isEssential: tab.getAttribute('zen-essential') === 'true', - parentUuid: tab.group?.getAttribute('zen-pin-id') || null, - position: tab._pPos, - }); - - tab.setAttribute('zen-pin-id', uuid); - tab.dispatchEvent( - new CustomEvent('ZenPinnedTabCreated', { - detail: { tab }, - }) - ); - - // This is used while migrating old pins to new system - we don't want to refresh when migrating - if (tab.getAttribute('zen-pinned-entry')) { - tab.removeAttribute('zen-pinned-entry'); - return; - } - this.onLocationChange(browser); - await this.refreshPinnedTabs(); - } - - async _removePinnedAttributes(tab, isClosing = false) { - tab.removeAttribute('zen-has-static-label'); - if (!tab.getAttribute('zen-pin-id') || this._temporarilyUnpiningEssential) { - return; - } - - if (Services.startup.shuttingDown || window.skipNextCanClose) { - return; - } - - this.log(`Removing pinned attributes for tab ${tab.getAttribute('zen-pin-id')}`); - await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id')); - this.resetPinChangedUrl(tab); - - if (!isClosing) { - tab.removeAttribute('zen-pin-id'); - tab.removeAttribute('zen-essential'); // Just in case - - if (!tab.hasAttribute('zen-workspace-id') && gZenWorkspaces.workspaceEnabled) { - const workspace = await gZenWorkspaces.getActiveWorkspace(); - tab.setAttribute('zen-workspace-id', workspace.uuid); - } - } - await this.refreshPinnedTabs(); - tab.dispatchEvent( - new CustomEvent('ZenPinnedTabRemoved', { - detail: { tab }, - }) - ); - } - _initClosePinnedTabShortcut() { let cmdClose = document.getElementById('cmd_close'); @@ -584,21 +186,6 @@ } } - async savePin(pin, notifyObservers = true) { - if (!this.hasInitializedPins && !gZenUIManager.testingEnabled) { - return; - } - const existingPin = this._pinsCache.find((p) => p.uuid === pin.uuid); - if (existingPin) { - Object.assign(existingPin, pin); - } else { - // We shouldn't need it, but just in case there's - // a race condition while making new pinned tabs. - this._pinsCache.push(pin); - } - await ZenPinnedTabsStorage.savePin(pin, notifyObservers); - } - async onCloseTabShortcut( event, selectedTab = gBrowser.selectedTab, @@ -821,12 +408,6 @@ tab.removeAttribute('zen-workspace-id'); } if (tab.pinned && tab.hasAttribute('zen-pin-id')) { - const pin = this._pinsCache.find((pin) => pin.uuid === tab.getAttribute('zen-pin-id')); - if (pin) { - pin.isEssential = true; - pin.workspaceUuid = null; - this.savePin(pin); - } gBrowser.zenHandleTabMove(tab, () => { if (tab.ownerGlobal !== window) { tab = gBrowser.adoptTab(tab, { @@ -1217,11 +798,8 @@ return document.documentElement.getAttribute('zen-sidebar-expanded') === 'true'; } - async updatePinTitle(tab, newTitle, isEdited = true, notifyObservers = true) { + async updatePinTitle(tab, newTitle, isEdited = true) { const uuid = tab.getAttribute('zen-pin-id'); - await ZenPinnedTabsStorage.updatePinTitle(uuid, newTitle, isEdited, notifyObservers); - - await this.refreshPinnedTabs(); const browsers = Services.wm.getEnumerator('navigator:browser'); diff --git a/src/zen/tabs/ZenPinnedTabsStorage.mjs b/src/zen/tabs/ZenPinnedTabsStorage.mjs deleted file mode 100644 index 425dbf2d1..000000000 --- a/src/zen/tabs/ZenPinnedTabsStorage.mjs +++ /dev/null @@ -1,635 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -var ZenPinnedTabsStorage = { - async init() { - await this._ensureTable(); - }, - - async _ensureTable() { - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage._ensureTable', async (db) => { - // Create the pins table if it doesn't exist - await db.execute(` - CREATE TABLE IF NOT EXISTS zen_pins ( - id INTEGER PRIMARY KEY, - uuid TEXT UNIQUE NOT NULL, - title TEXT NOT NULL, - url TEXT, - container_id INTEGER, - workspace_uuid TEXT, - position INTEGER NOT NULL DEFAULT 0, - is_essential BOOLEAN NOT NULL DEFAULT 0, - is_group BOOLEAN NOT NULL DEFAULT 0, - created_at INTEGER NOT NULL, - updated_at INTEGER NOT NULL - ) - `); - - const columns = await db.execute(`PRAGMA table_info(zen_pins)`); - const columnNames = columns.map((row) => row.getResultByName('name')); - - // Helper function to add column if it doesn't exist - const addColumnIfNotExists = async (columnName, definition) => { - if (!columnNames.includes(columnName)) { - await db.execute(`ALTER TABLE zen_pins ADD COLUMN ${columnName} ${definition}`); - } - }; - - await addColumnIfNotExists('edited_title', 'BOOLEAN NOT NULL DEFAULT 0'); - await addColumnIfNotExists('is_folder_collapsed', 'BOOLEAN NOT NULL DEFAULT 0'); - await addColumnIfNotExists('folder_icon', 'TEXT DEFAULT NULL'); - await addColumnIfNotExists('folder_parent_uuid', 'TEXT DEFAULT NULL'); - - await db.execute(` - CREATE INDEX IF NOT EXISTS idx_zen_pins_uuid ON zen_pins(uuid) - `); - - await db.execute(` - CREATE TABLE IF NOT EXISTS zen_pins_changes ( - uuid TEXT PRIMARY KEY, - timestamp INTEGER NOT NULL - ) - `); - - await db.execute(` - CREATE INDEX IF NOT EXISTS idx_zen_pins_changes_uuid ON zen_pins_changes(uuid) - `); - - this._resolveInitialized(); - }); - }, - - /** - * Private helper method to notify observers with a list of changed UUIDs. - * @param {string} event - The observer event name. - * @param {Array} uuids - Array of changed workspace UUIDs. - */ - _notifyPinsChanged(event, uuids) { - if (uuids.length === 0) return; // No changes to notify - - // Convert the array of UUIDs to a JSON string - const data = JSON.stringify(uuids); - - Services.obs.notifyObservers(null, event, data); - }, - - async savePin(pin, notifyObservers = true) { - const changedUUIDs = new Set(); - - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.savePin', async (db) => { - await db.executeTransaction(async () => { - const now = Date.now(); - - let newPosition; - if ('position' in pin && Number.isFinite(pin.position)) { - newPosition = pin.position; - } else { - // Get the maximum position within the same parent group (or null for root level) - const maxPositionResult = await db.execute( - ` - SELECT MAX("position") as max_position - FROM zen_pins - WHERE COALESCE(folder_parent_uuid, '') = COALESCE(:folder_parent_uuid, '') - `, - { folder_parent_uuid: pin.parentUuid || null } - ); - const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; - newPosition = maxPosition + 1000; - } - - // Insert or replace the pin - await db.executeCached( - ` - INSERT OR REPLACE INTO zen_pins ( - uuid, title, url, container_id, workspace_uuid, position, - is_essential, is_group, folder_parent_uuid, edited_title, created_at, - updated_at, is_folder_collapsed, folder_icon - ) VALUES ( - :uuid, :title, :url, :container_id, :workspace_uuid, :position, - :is_essential, :is_group, :folder_parent_uuid, :edited_title, - COALESCE((SELECT created_at FROM zen_pins WHERE uuid = :uuid), :now), - :now, :is_folder_collapsed, :folder_icon - ) - `, - { - uuid: pin.uuid, - title: pin.title, - url: pin.isGroup ? '' : pin.url, - container_id: pin.containerTabId || null, - workspace_uuid: pin.workspaceUuid || null, - position: newPosition, - is_essential: pin.isEssential || false, - is_group: pin.isGroup || false, - folder_parent_uuid: pin.parentUuid || null, - edited_title: pin.editedTitle || false, - now, - folder_icon: pin.folderIcon || null, - is_folder_collapsed: pin.isFolderCollapsed || false, - } - ); - - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid: pin.uuid, - timestamp: Math.floor(now / 1000), - } - ); - - changedUUIDs.add(pin.uuid); - await this.updateLastChangeTimestamp(db); - }); - }); - - if (notifyObservers) { - this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); - } - }, - - async getPins() { - const db = await PlacesUtils.promiseDBConnection(); - const rows = await db.executeCached(` - SELECT * FROM zen_pins - ORDER BY position ASC - `); - return rows.map((row) => ({ - uuid: row.getResultByName('uuid'), - title: row.getResultByName('title'), - url: row.getResultByName('url'), - containerTabId: row.getResultByName('container_id'), - workspaceUuid: row.getResultByName('workspace_uuid'), - position: row.getResultByName('position'), - isEssential: Boolean(row.getResultByName('is_essential')), - isGroup: Boolean(row.getResultByName('is_group')), - parentUuid: row.getResultByName('folder_parent_uuid'), - editedTitle: Boolean(row.getResultByName('edited_title')), - folderIcon: row.getResultByName('folder_icon'), - isFolderCollapsed: Boolean(row.getResultByName('is_folder_collapsed')), - })); - }, - - /** - * Create a new group - * @param {string} title - The title of the group - * @param {string} workspaceUuid - The workspace UUID (optional) - * @param {string} parentUuid - The parent group UUID (optional, null for root level) - * @param {number} position - The position of the group (optional, will auto-calculate if not provided) - * @param {boolean} notifyObservers - Whether to notify observers (default: true) - * @returns {Promise} The UUID of the created group - */ - async createGroup( - title, - icon = null, - isCollapsed = false, - workspaceUuid = null, - parentUuid = null, - position = null, - notifyObservers = true - ) { - if (!title || typeof title !== 'string') { - throw new Error('Group title is required and must be a string'); - } - - const groupUuid = gZenUIManager.generateUuidv4(); - - const groupPin = { - uuid: groupUuid, - title, - folderIcon: icon || null, - isFolderCollapsed: isCollapsed || false, - workspaceUuid, - parentUuid, - position, - isGroup: true, - isEssential: false, - editedTitle: true, // Group titles are always considered edited - }; - - await this.savePin(groupPin, notifyObservers); - return groupUuid; - }, - - /** - * Add an existing tab/pin to a group - * @param {string} tabUuid - The UUID of the tab to add to the group - * @param {string} groupUuid - The UUID of the target group - * @param {number} position - The position within the group (optional, will append if not provided) - * @param {boolean} notifyObservers - Whether to notify observers (default: true) - */ - async addTabToGroup(tabUuid, groupUuid, position = null, notifyObservers = true) { - if (!tabUuid || !groupUuid) { - throw new Error('Both tabUuid and groupUuid are required'); - } - - const changedUUIDs = new Set(); - - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.addTabToGroup', async (db) => { - await db.executeTransaction(async () => { - // Verify the group exists and is actually a group - const groupCheck = await db.execute( - `SELECT is_group FROM zen_pins WHERE uuid = :groupUuid`, - { groupUuid } - ); - - if (groupCheck.length === 0) { - throw new Error(`Group with UUID ${groupUuid} does not exist`); - } - - if (!groupCheck[0].getResultByName('is_group')) { - throw new Error(`Pin with UUID ${groupUuid} is not a group`); - } - - const tabCheck = await db.execute(`SELECT uuid FROM zen_pins WHERE uuid = :tabUuid`, { - tabUuid, - }); - - if (tabCheck.length === 0) { - throw new Error(`Tab with UUID ${tabUuid} does not exist`); - } - - const now = Date.now(); - let newPosition; - - if (position !== null && Number.isFinite(position)) { - newPosition = position; - } else { - // Get the maximum position within the group - const maxPositionResult = await db.execute( - `SELECT MAX("position") as max_position FROM zen_pins WHERE folder_parent_uuid = :groupUuid`, - { groupUuid } - ); - const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; - newPosition = maxPosition + 1000; - } - - await db.execute( - ` - UPDATE zen_pins - SET folder_parent_uuid = :groupUuid, - position = :newPosition, - updated_at = :now - WHERE uuid = :tabUuid - `, - { - tabUuid, - groupUuid, - newPosition, - now, - } - ); - - changedUUIDs.add(tabUuid); - - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid: tabUuid, - timestamp: Math.floor(now / 1000), - } - ); - - await this.updateLastChangeTimestamp(db); - }); - }); - - if (notifyObservers) { - this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); - } - }, - - /** - * Remove a tab from its group (move to root level) - * @param {string} tabUuid - The UUID of the tab to remove from its group - * @param {number} newPosition - The new position at root level (optional, will append if not provided) - * @param {boolean} notifyObservers - Whether to notify observers (default: true) - */ - async removeTabFromGroup(tabUuid, newPosition = null, notifyObservers = true) { - if (!tabUuid) { - throw new Error('tabUuid is required'); - } - - const changedUUIDs = new Set(); - - await PlacesUtils.withConnectionWrapper( - 'ZenPinnedTabsStorage.removeTabFromGroup', - async (db) => { - await db.executeTransaction(async () => { - // Verify the tab exists and is in a group - const tabCheck = await db.execute( - `SELECT folder_parent_uuid FROM zen_pins WHERE uuid = :tabUuid`, - { tabUuid } - ); - - if (tabCheck.length === 0) { - throw new Error(`Tab with UUID ${tabUuid} does not exist`); - } - - if (!tabCheck[0].getResultByName('folder_parent_uuid')) { - return; - } - - const now = Date.now(); - let finalPosition; - - if (newPosition !== null && Number.isFinite(newPosition)) { - finalPosition = newPosition; - } else { - // Get the maximum position at root level (where folder_parent_uuid is null) - const maxPositionResult = await db.execute( - `SELECT MAX("position") as max_position FROM zen_pins WHERE folder_parent_uuid IS NULL` - ); - const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; - finalPosition = maxPosition + 1000; - } - - // Update the tab to be at root level - await db.execute( - ` - UPDATE zen_pins - SET folder_parent_uuid = NULL, - position = :newPosition, - updated_at = :now - WHERE uuid = :tabUuid - `, - { - tabUuid, - newPosition: finalPosition, - now, - } - ); - - changedUUIDs.add(tabUuid); - - // Record the change - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid: tabUuid, - timestamp: Math.floor(now / 1000), - } - ); - - await this.updateLastChangeTimestamp(db); - }); - } - ); - - if (notifyObservers) { - this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); - } - }, - - async removePin(uuid, notifyObservers = true) { - const changedUUIDs = [uuid]; - - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.removePin', async (db) => { - await db.executeTransaction(async () => { - // Get all child UUIDs first for change tracking - const children = await db.execute( - `SELECT uuid FROM zen_pins WHERE folder_parent_uuid = :uuid`, - { - uuid, - } - ); - - // Add child UUIDs to changedUUIDs array - for (const child of children) { - changedUUIDs.push(child.getResultByName('uuid')); - } - - // Delete the pin/group itself - await db.execute(`DELETE FROM zen_pins WHERE uuid = :uuid`, { uuid }); - - // Record the changes - const now = Math.floor(Date.now() / 1000); - for (const changedUuid of changedUUIDs) { - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid: changedUuid, - timestamp: now, - } - ); - } - - await this.updateLastChangeTimestamp(db); - }); - }); - - if (notifyObservers) { - this._notifyPinsChanged('zen-pin-removed', changedUUIDs); - } - }, - - async wipeAllPins() { - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.wipeAllPins', async (db) => { - await db.execute(`DELETE FROM zen_pins`); - await db.execute(`DELETE FROM zen_pins_changes`); - await this.updateLastChangeTimestamp(db); - }); - }, - - async markChanged(uuid) { - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.markChanged', async (db) => { - const now = Date.now(); - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid, - timestamp: Math.floor(now / 1000), - } - ); - }); - }, - - async getChangedIDs() { - const db = await PlacesUtils.promiseDBConnection(); - const rows = await db.execute(` - SELECT uuid, timestamp FROM zen_pins_changes - `); - const changes = {}; - for (const row of rows) { - changes[row.getResultByName('uuid')] = row.getResultByName('timestamp'); - } - return changes; - }, - - async clearChangedIDs() { - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.clearChangedIDs', async (db) => { - await db.execute(`DELETE FROM zen_pins_changes`); - }); - }, - - shouldReorderPins(before, current, after) { - const minGap = 1; // Minimum allowed gap between positions - return ( - (before !== null && current - before < minGap) || (after !== null && after - current < minGap) - ); - }, - - async reorderAllPins(db, changedUUIDs) { - const pins = await db.execute(` - SELECT uuid - FROM zen_pins - ORDER BY position ASC - `); - - for (let i = 0; i < pins.length; i++) { - const newPosition = (i + 1) * 1000; // Use large increments - await db.execute( - ` - UPDATE zen_pins - SET position = :newPosition - WHERE uuid = :uuid - `, - { newPosition, uuid: pins[i].getResultByName('uuid') } - ); - changedUUIDs.add(pins[i].getResultByName('uuid')); - } - }, - - async updateLastChangeTimestamp(db) { - const now = Date.now(); - await db.execute( - ` - INSERT OR REPLACE INTO moz_meta (key, value) - VALUES ('zen_pins_last_change', :now) - `, - { now } - ); - }, - - async getLastChangeTimestamp() { - const db = await PlacesUtils.promiseDBConnection(); - const result = await db.executeCached(` - SELECT value FROM moz_meta WHERE key = 'zen_pins_last_change' - `); - return result.length ? parseInt(result[0].getResultByName('value'), 10) : 0; - }, - - async updatePinPositions(pins) { - const changedUUIDs = new Set(); - - await PlacesUtils.withConnectionWrapper( - 'ZenPinnedTabsStorage.updatePinPositions', - async (db) => { - await db.executeTransaction(async () => { - const now = Date.now(); - - for (let i = 0; i < pins.length; i++) { - const pin = pins[i]; - const newPosition = (i + 1) * 1000; - - await db.execute( - ` - UPDATE zen_pins - SET position = :newPosition - WHERE uuid = :uuid - `, - { newPosition, uuid: pin.uuid } - ); - - changedUUIDs.add(pin.uuid); - - // Record the change - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid: pin.uuid, - timestamp: Math.floor(now / 1000), - } - ); - } - - await this.updateLastChangeTimestamp(db); - }); - } - ); - - this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); - }, - - async updatePinTitle(uuid, newTitle, isEdited = true, notifyObservers = true) { - if (!uuid || typeof newTitle !== 'string') { - throw new Error('Invalid parameters: uuid and newTitle are required'); - } - - const changedUUIDs = new Set(); - - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.updatePinTitle', async (db) => { - await db.executeTransaction(async () => { - const now = Date.now(); - - // Update the pin's title and edited_title flag - const result = await db.execute( - ` - UPDATE zen_pins - SET title = :newTitle, - edited_title = :isEdited, - updated_at = :now - WHERE uuid = :uuid - `, - { - uuid, - newTitle, - isEdited, - now, - } - ); - - // Only proceed with change tracking if a row was actually updated - if (result.rowsAffected > 0) { - changedUUIDs.add(uuid); - - // Record the change - await db.execute( - ` - INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) - VALUES (:uuid, :timestamp) - `, - { - uuid, - timestamp: Math.floor(now / 1000), - } - ); - - await this.updateLastChangeTimestamp(db); - } - }); - }); - - if (notifyObservers && changedUUIDs.size > 0) { - this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); - } - }, - - async __dropTables() { - await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.__dropTables', async (db) => { - await db.execute(`DROP TABLE IF EXISTS zen_pins`); - await db.execute(`DROP TABLE IF EXISTS zen_pins_changes`); - }); - }, -}; - -ZenPinnedTabsStorage.promiseInitialized = new Promise((resolve) => { - ZenPinnedTabsStorage._resolveInitialized = resolve; - ZenPinnedTabsStorage.init(); -}); diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs index 857f9fc9c..4c06ae0e0 100644 --- a/src/zen/workspaces/ZenWindowSyncing.mjs +++ b/src/zen/workspaces/ZenWindowSyncing.mjs @@ -293,14 +293,14 @@ targetTab.getAttribute('zen-workspace-id') ); } - duplicatedTab.setAttribute('zen-pin-id', targetTab.getAttribute('zen-pin-id')); duplicatedTab.setAttribute('zen-sync-id', targetTab.getAttribute('zen-sync-id')); } #onTabGroupCreate(event) { - const targetGroup = event.target; - const isSplitView = targetGroup.classList.contains('zen-split-view'); - const isFolder = targetGroup.isZenFolder; + void event; + //const targetGroup = event.target; + //const isSplitView = targetGroup.classList.contains('zen-split-view'); + //const isFolder = targetGroup.isZenFolder; } } diff --git a/src/zen/workspaces/ZenWorkspaces.mjs b/src/zen/workspaces/ZenWorkspaces.mjs index a54c1ebfe..f19ba7277 100644 --- a/src/zen/workspaces/ZenWorkspaces.mjs +++ b/src/zen/workspaces/ZenWorkspaces.mjs @@ -932,7 +932,6 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature { await this.workspaceBookmarks(); await this.initializeTabsStripSections(); this._initializeEmptyTab(); - await gZenPinnedTabManager.refreshPinnedTabs({ init: true }); await this.changeWorkspace(activeWorkspace, { onInit: true }); this.#fixTabPositions(); this.onWindowResize(); @@ -1471,11 +1470,6 @@ var gZenWorkspaces = new (class extends nsZenMultiWindowFeature { !tab.hasAttribute('zen-empty-tab') && !tab.hasAttribute('zen-essential') ); - for (const tab of tabs) { - if (tab.pinned) { - await ZenPinnedTabsStorage.removePin(tab.getAttribute('zen-pin-id')); - } - } gBrowser.removeTabs(tabs, { animate: false, skipSessionStore: true, From bf1b0dcd4848a9b3846b75276797e4a3b0fa9a7b Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sat, 1 Nov 2025 13:40:14 +0100 Subject: [PATCH 09/18] feat: Dont restore windows that are already initialized, b=no-bug, c=no-component --- .../sessionstore/SessionStore-sys-mjs.patch | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index ef89b7892..e92e6ec41 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index eb62ff3e733e43fdaa299babddea3ba0125abb06..1ca2e7327e72824805a93c18cb7e3dfd499c66d7 100644 +index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03cda47b6f 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -126,6 +126,8 @@ const TAB_EVENTS = [ @@ -28,18 +28,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..1ca2e7327e72824805a93c18cb7e3dfd this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2041,6 +2046,10 @@ var SessionStoreInternal = { - // A regular window is not a private window, taskbar tab window, or popup window - let isRegularWindow = - !isPrivateWindow && !isTaskbarTab && aWindow.toolbar.visible; -+ if (!aInitialState && isRegularWindow) { -+ aInitialState = lazy.ZenSessionStore.getNewWindowData(this._windows); -+ this.restoreWindows(aWindow, aInitialState, {}); -+ } - - // perform additional initialization when the first window is loading - if (lazy.RunState.isStopped) { -@@ -2139,7 +2148,6 @@ var SessionStoreInternal = { +@@ -2139,7 +2144,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -47,6 +36,17 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..1ca2e7327e72824805a93c18cb7e3dfd !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. +@@ -2203,6 +2207,10 @@ var SessionStoreInternal = { + }); + this._shouldRestoreLastSession = false; + } ++ else if (!aInitialState && isRegularWindow) { ++ aInitialState = lazy.ZenSessionStore.getNewWindowData(this._windows); ++ this.restoreWindows(aWindow, aInitialState, {}); ++ } + + if (this._restoreLastWindow && aWindow.toolbar.visible) { + // always reset (if not a popup window) @@ -2372,11 +2380,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } From c4dd4708647913ddb5045c7969da818df37031b5 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Thu, 13 Nov 2025 13:56:31 +0100 Subject: [PATCH 10/18] chore: Update patches to ff 145, b=no-bug, c=no-component --- .../sessionstore/SessionStore-sys-mjs.patch | 40 +++--- .../tabbrowser/content/tab-js.patch | 18 +-- .../tabbrowser/content/tabbrowser-js.patch | 134 +++++++++--------- 3 files changed, 96 insertions(+), 96 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index e92e6ec41..7c625f2af 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,17 +1,17 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03cda47b6f 100644 +index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be523e4feb 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs -@@ -126,6 +126,8 @@ const TAB_EVENTS = [ - "TabUngrouped", +@@ -127,6 +127,8 @@ const TAB_EVENTS = [ "TabGroupCollapse", "TabGroupExpand", + "TabSplitViewActivate", + "TabAddedToEssentials", + "TabRemovedFromEssentials", ]; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -@@ -195,6 +197,7 @@ ChromeUtils.defineESModuleGetters(lazy, { +@@ -196,6 +198,7 @@ ChromeUtils.defineESModuleGetters(lazy, { TabStateCache: "resource:///modules/sessionstore/TabStateCache.sys.mjs", TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.sys.mjs", setTimeout: "resource://gre/modules/Timer.sys.mjs", @@ -19,7 +19,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 }); ChromeUtils.defineLazyGetter(lazy, "blankURI", () => { -@@ -1904,6 +1907,8 @@ var SessionStoreInternal = { +@@ -1911,6 +1914,8 @@ var SessionStoreInternal = { case "TabPinned": case "TabUnpinned": case "SwapDocShells": @@ -28,7 +28,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2139,7 +2144,6 @@ var SessionStoreInternal = { +@@ -2151,7 +2156,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -36,7 +36,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2203,6 +2207,10 @@ var SessionStoreInternal = { +@@ -2215,6 +2219,10 @@ var SessionStoreInternal = { }); this._shouldRestoreLastSession = false; } @@ -47,7 +47,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 if (this._restoreLastWindow && aWindow.toolbar.visible) { // always reset (if not a popup window) -@@ -2372,11 +2380,9 @@ var SessionStoreInternal = { +@@ -2384,11 +2392,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } @@ -59,7 +59,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 // Store the window's close date to figure out when each individual tab // was closed. This timestamp should allow re-arranging data based on how -@@ -3361,7 +3367,7 @@ var SessionStoreInternal = { +@@ -3373,7 +3379,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -68,7 +68,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 return; } -@@ -4073,6 +4079,11 @@ var SessionStoreInternal = { +@@ -4089,6 +4095,11 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -80,7 +80,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4509,6 +4520,7 @@ var SessionStoreInternal = { +@@ -4525,6 +4536,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -88,7 +88,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5358,7 +5370,7 @@ var SessionStoreInternal = { +@@ -5374,7 +5386,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -97,7 +97,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 removableTabs.push(tab); } } -@@ -5418,7 +5430,7 @@ var SessionStoreInternal = { +@@ -5434,7 +5446,7 @@ var SessionStoreInternal = { } let workspaceID = aWindow.getWorkspaceID(); @@ -106,7 +106,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 winData.workspaceID = workspaceID; } }, -@@ -5609,11 +5621,12 @@ var SessionStoreInternal = { +@@ -5625,11 +5637,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -120,7 +120,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5624,6 +5637,7 @@ var SessionStoreInternal = { +@@ -5640,6 +5653,7 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -128,7 +128,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5636,7 +5650,7 @@ var SessionStoreInternal = { +@@ -5652,7 +5666,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -137,7 +137,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5748,8 +5762,8 @@ var SessionStoreInternal = { +@@ -5764,8 +5778,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -148,7 +148,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5792,6 +5806,8 @@ var SessionStoreInternal = { +@@ -5808,6 +5822,8 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -157,7 +157,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6348,6 +6364,25 @@ var SessionStoreInternal = { +@@ -6371,6 +6387,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -183,7 +183,7 @@ index eb62ff3e733e43fdaa299babddea3ba0125abb06..6a73ee56c067cba2347a552b4152cd03 if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7263,7 +7298,7 @@ var SessionStoreInternal = { +@@ -7289,7 +7324,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { diff --git a/src/browser/components/tabbrowser/content/tab-js.patch b/src/browser/components/tabbrowser/content/tab-js.patch index f9f19d12d..75153b173 100644 --- a/src/browser/components/tabbrowser/content/tab-js.patch +++ b/src/browser/components/tabbrowser/content/tab-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tab.js b/browser/components/tabbrowser/content/tab.js -index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362efc001afdd 100644 +index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577b5fad08c 100644 --- a/browser/components/tabbrowser/content/tab.js +++ b/browser/components/tabbrowser/content/tab.js @@ -21,6 +21,7 @@ @@ -42,7 +42,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef ".tab-label-container": "pinned,selected=visuallyselected,labeldirection", ".tab-label": -@@ -184,7 +187,7 @@ +@@ -186,7 +189,7 @@ } set _visuallySelected(val) { @@ -51,7 +51,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef return; } -@@ -220,11 +223,21 @@ +@@ -222,11 +225,21 @@ } get visible() { @@ -78,7 +78,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef } get hidden() { -@@ -295,7 +308,7 @@ +@@ -297,7 +310,7 @@ return false; } @@ -87,7 +87,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef } get lastAccessed() { -@@ -372,8 +385,11 @@ +@@ -374,8 +387,11 @@ } get group() { @@ -101,7 +101,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef } return null; } -@@ -468,6 +484,8 @@ +@@ -470,6 +486,8 @@ this.style.MozUserFocus = "ignore"; } else if ( event.target.classList.contains("tab-close-button") || @@ -110,7 +110,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef event.target.classList.contains("tab-icon-overlay") || event.target.classList.contains("tab-audio-button") ) { -@@ -522,6 +540,10 @@ +@@ -524,6 +542,10 @@ this.style.MozUserFocus = ""; } @@ -121,7 +121,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef on_click(event) { if (event.button != 0) { return; -@@ -582,6 +605,14 @@ +@@ -584,6 +607,14 @@ // (see tabbrowser-tabs 'click' handler). gBrowser.tabContainer._blockDblClick = true; } @@ -136,7 +136,7 @@ index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362ef } on_dblclick(event) { -@@ -605,6 +636,8 @@ +@@ -607,6 +638,8 @@ animate: true, triggeringEvent: event, }); diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index ccccb80c7..2b2a58d5d 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,8 +1,8 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394b7dbc6a7 100644 +index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc349868d0d0 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js -@@ -432,15 +432,64 @@ +@@ -450,15 +450,64 @@ return this.tabContainer.visibleTabs; } @@ -69,7 +69,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 set selectedTab(val) { if ( gSharedTabWarning.willShowSharedTabWarning(val) || -@@ -588,6 +637,7 @@ +@@ -613,6 +662,7 @@ this.tabpanels.appendChild(panel); let tab = this.tabs[0]; @@ -77,7 +77,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 tab.linkedPanel = uniqueId; this._selectedTab = tab; this._selectedBrowser = browser; -@@ -873,13 +923,17 @@ +@@ -898,13 +948,17 @@ } this.showTab(aTab); @@ -96,7 +96,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 aTab.setAttribute("pinned", "true"); this._updateTabBarForPinnedTabs(); -@@ -892,11 +946,15 @@ +@@ -917,11 +971,15 @@ } this.#handleTabMove(aTab, () => { @@ -113,7 +113,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 }); aTab.style.marginInlineStart = ""; -@@ -1073,6 +1131,8 @@ +@@ -1098,6 +1156,8 @@ let LOCAL_PROTOCOLS = ["chrome:", "about:", "resource:", "data:"]; @@ -122,7 +122,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if ( aIconURL && !LOCAL_PROTOCOLS.some(protocol => aIconURL.startsWith(protocol)) -@@ -1082,6 +1142,9 @@ +@@ -1107,6 +1167,9 @@ ); return; } @@ -132,7 +132,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 let browser = this.getBrowserForTab(aTab); browser.mIconURL = aIconURL; -@@ -1445,6 +1508,7 @@ +@@ -1470,6 +1533,7 @@ if (!this._previewMode) { newTab.recordTimeFromUnloadToReload(); newTab.updateLastAccessed(); @@ -140,7 +140,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 oldTab.updateLastAccessed(); // if this is the foreground window, update the last-seen timestamps. if (this.ownerGlobal == BrowserWindowTracker.getTopWindow()) { -@@ -1597,6 +1661,9 @@ +@@ -1622,6 +1686,9 @@ } let activeEl = document.activeElement; @@ -150,7 +150,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // If focus is on the old tab, move it to the new tab. if (activeEl == oldTab) { newTab.focus(); -@@ -1920,7 +1987,8 @@ +@@ -1945,7 +2012,8 @@ } _setTabLabel(aTab, aLabel, { beforeTabOpen, isContentTitle, isURL } = {}) { @@ -160,7 +160,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 return false; } -@@ -2028,7 +2096,7 @@ +@@ -2053,7 +2121,7 @@ newIndex = this.selectedTab._tPos + 1; } @@ -169,7 +169,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (this.isTabGroupLabel(targetTab)) { throw new Error( "Replacing a tab group label with a tab is not supported" -@@ -2303,6 +2371,7 @@ +@@ -2328,6 +2396,7 @@ uriIsAboutBlank, userContextId, skipLoad, @@ -177,7 +177,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } = {}) { let b = document.createXULElement("browser"); // Use the JSM global to create the permanentKey, so that if the -@@ -2376,8 +2445,7 @@ +@@ -2401,8 +2470,7 @@ // we use a different attribute name for this? b.setAttribute("name", name); } @@ -187,7 +187,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 b.setAttribute("transparent", "true"); } -@@ -2542,7 +2610,7 @@ +@@ -2567,7 +2635,7 @@ let panel = this.getPanel(browser); let uniqueId = this._generateUniquePanelID(); @@ -196,7 +196,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 aTab.linkedPanel = uniqueId; // Inject the into the DOM if necessary. -@@ -2601,8 +2669,8 @@ +@@ -2626,8 +2694,8 @@ // If we transitioned from one browser to two browsers, we need to set // hasSiblings=false on both the existing browser and the new browser. if (this.tabs.length == 2) { @@ -207,7 +207,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else { aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1; } -@@ -2779,7 +2847,6 @@ +@@ -2814,7 +2882,6 @@ this.selectedTab = this.addTrustedTab(BROWSER_NEW_TAB_URL, { tabIndex: tab._tPos + 1, userContextId: tab.userContextId, @@ -215,7 +215,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 focusUrlBar: true, }); resolve(this.selectedBrowser); -@@ -2859,6 +2926,8 @@ +@@ -2923,6 +2990,8 @@ schemelessInput, hasValidUserGestureActivation = false, textDirectiveUserActivation = false, @@ -224,7 +224,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } = {} ) { // all callers of addTab that pass a params object need to pass -@@ -2869,6 +2938,12 @@ +@@ -2933,6 +3002,12 @@ ); } @@ -237,7 +237,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (!UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.start("browser.tabs.opening", "initting", window); } -@@ -2932,6 +3007,19 @@ +@@ -2996,6 +3071,19 @@ noInitialLabel, skipBackgroundNotify, }); @@ -257,7 +257,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (insertTab) { // Insert the tab into the tab container in the correct position. this.#insertTabAtIndex(t, { -@@ -2940,6 +3028,7 @@ +@@ -3004,6 +3092,7 @@ ownerTab, openerTab, pinned, @@ -265,7 +265,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 bulkOrderedOpen, tabGroup: tabGroup ?? openerTab?.group, }); -@@ -2958,6 +3047,7 @@ +@@ -3022,6 +3111,7 @@ openWindowInfo, skipLoad, triggeringRemoteType, @@ -273,7 +273,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 })); if (focusUrlBar) { -@@ -3078,6 +3168,12 @@ +@@ -3146,6 +3236,12 @@ } } @@ -286,7 +286,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // Additionally send pinned tab events if (pinned) { this.#notifyPinnedStatus(t); -@@ -3248,10 +3344,10 @@ +@@ -3330,10 +3426,10 @@ isAdoptingGroup = false, isUserTriggered = false, telemetryUserCreateSource = "unknown", @@ -298,7 +298,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } if (!color) { -@@ -3272,9 +3368,14 @@ +@@ -3354,9 +3450,14 @@ label, isAdoptingGroup ); @@ -315,7 +315,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 ); group.addTabs(tabs); -@@ -3395,7 +3496,7 @@ +@@ -3477,7 +3578,7 @@ } this.#handleTabMove(tab, () => @@ -324,7 +324,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 ); } -@@ -3597,6 +3698,7 @@ +@@ -3679,6 +3780,7 @@ openWindowInfo, skipLoad, triggeringRemoteType, @@ -332,7 +332,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } ) { // If we don't have a preferred remote type (or it is `NOT_REMOTE`), and -@@ -3666,6 +3768,7 @@ +@@ -3748,6 +3850,7 @@ openWindowInfo, name, skipLoad, @@ -340,7 +340,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 }); } -@@ -3853,7 +3956,7 @@ +@@ -3935,7 +4038,7 @@ // Add a new tab if needed. if (!tab) { let createLazyBrowser = @@ -349,7 +349,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 let url = "about:blank"; if (tabData.entries?.length) { -@@ -3890,8 +3993,10 @@ +@@ -3972,8 +4075,10 @@ insertTab: false, skipLoad: true, preferredRemoteType, @@ -361,7 +361,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (select) { tabToSelect = tab; } -@@ -3903,7 +4008,8 @@ +@@ -3985,7 +4090,8 @@ this.pinTab(tab); // Then ensure all the tab open/pinning information is sent. this._fireTabOpen(tab, {}); @@ -371,7 +371,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 let { groupId } = tabData; const tabGroup = tabGroupWorkingData.get(groupId); // if a tab refers to a tab group we don't know, skip any group -@@ -3917,7 +4023,10 @@ +@@ -3999,7 +4105,10 @@ tabGroup.stateData.id, tabGroup.stateData.color, tabGroup.stateData.collapsed, @@ -383,7 +383,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 ); tabsFragment.appendChild(tabGroup.node); } -@@ -3962,9 +4071,23 @@ +@@ -4044,9 +4153,23 @@ // to remove the old selected tab. if (tabToSelect) { let leftoverTab = this.selectedTab; @@ -407,7 +407,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (tabs.length > 1 || !tabs[0].selected) { this._updateTabsAfterInsert(); -@@ -4155,11 +4278,14 @@ +@@ -4237,11 +4360,14 @@ if (ownerTab) { tab.owner = ownerTab; } @@ -423,7 +423,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if ( !bulkOrderedOpen && ((openerTab && -@@ -4171,7 +4297,7 @@ +@@ -4253,7 +4379,7 @@ let lastRelatedTab = openerTab && this._lastRelatedTabMap.get(openerTab); let previousTab = lastRelatedTab || openerTab || this.selectedTab; @@ -432,7 +432,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 tabGroup = previousTab.group; } if ( -@@ -4182,7 +4308,7 @@ +@@ -4264,7 +4390,7 @@ ) { elementIndex = Infinity; } else if (previousTab.visible) { @@ -441,7 +441,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else if (previousTab == FirefoxViewHandler.tab) { elementIndex = 0; } -@@ -4210,14 +4336,14 @@ +@@ -4292,14 +4418,14 @@ } // Ensure index is within bounds. if (tab.pinned) { @@ -460,7 +460,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (pinned && !itemAfter?.pinned) { itemAfter = null; -@@ -4228,7 +4354,7 @@ +@@ -4310,7 +4436,7 @@ this.tabContainer._invalidateCachedTabs(); @@ -469,7 +469,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4264,6 +4390,7 @@ +@@ -4346,6 +4472,7 @@ if (pinned) { this._updateTabBarForPinnedTabs(); } @@ -477,7 +477,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 TabBarVisibility.update(); } -@@ -4814,6 +4944,7 @@ +@@ -4896,6 +5026,7 @@ telemetrySource, } = {} ) { @@ -485,7 +485,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4903,6 +5034,7 @@ +@@ -4985,6 +5116,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -493,7 +493,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } catch (e) { console.error(e); } -@@ -4941,6 +5073,12 @@ +@@ -5023,6 +5155,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -506,7 +506,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -4955,6 +5093,9 @@ +@@ -5037,6 +5175,9 @@ // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; let isLastTab = this.#isLastTabInWindow(aTab); @@ -516,7 +516,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -5003,7 +5144,13 @@ +@@ -5085,7 +5226,13 @@ // We're not animating, so we can cancel the animation stopwatch. Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId); aTab._closeTimeAnimTimerId = null; @@ -531,7 +531,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 return; } -@@ -5137,7 +5284,7 @@ +@@ -5219,7 +5366,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -540,7 +540,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -5161,6 +5308,7 @@ +@@ -5243,6 +5390,7 @@ newTab = true; } @@ -548,7 +548,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -5201,13 +5349,7 @@ +@@ -5283,13 +5431,7 @@ aTab._mouseleave(); if (newTab) { @@ -563,7 +563,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else { TabBarVisibility.update(); } -@@ -5340,6 +5482,7 @@ +@@ -5422,6 +5564,7 @@ this.tabs[i]._tPos = i; } @@ -571,7 +571,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (!this._windowIsClosing) { // update tab close buttons state this.tabContainer._updateCloseButtons(); -@@ -5552,6 +5695,7 @@ +@@ -5643,6 +5786,7 @@ } let excludeTabs = new Set(aExcludeTabs); @@ -579,7 +579,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // If this tab has a successor, it should be selectable, since // hiding or closing a tab removes that tab as a successor. -@@ -5564,13 +5708,13 @@ +@@ -5655,13 +5799,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -595,7 +595,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5586,7 +5730,7 @@ +@@ -5677,7 +5821,7 @@ } if (tab) { @@ -604,7 +604,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5607,7 +5751,7 @@ +@@ -5698,7 +5842,7 @@ }); } @@ -613,7 +613,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } _blurTab(aTab) { -@@ -6013,10 +6157,10 @@ +@@ -6104,10 +6248,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -626,7 +626,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6075,6 +6219,7 @@ +@@ -6166,6 +6310,7 @@ * @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab */ replaceTabWithWindow(aTab, aOptions) { @@ -634,7 +634,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (this.tabs.length == 1) { return null; } -@@ -6208,7 +6353,7 @@ +@@ -6299,7 +6444,7 @@ * `true` if element is a `` */ isTabGroup(element) { @@ -643,7 +643,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } /** -@@ -6284,8 +6429,8 @@ +@@ -6375,8 +6520,8 @@ } // Don't allow mixing pinned and unpinned tabs. @@ -654,7 +654,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6311,10 +6456,16 @@ +@@ -6402,10 +6547,16 @@ this.#handleTabMove( element, () => { @@ -673,7 +673,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6372,23 +6523,28 @@ +@@ -6463,23 +6614,28 @@ #moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) { if (this.isTabGroupLabel(targetElement)) { targetElement = targetElement.group; @@ -708,7 +708,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else if (!element.pinned && targetElement && targetElement.pinned) { // If the caller asks to move an unpinned element next to a pinned // tab, move the unpinned element to be the first unpinned element -@@ -6401,14 +6557,34 @@ +@@ -6492,14 +6648,34 @@ // move the tab group right before the first unpinned tab. // 4. Moving a tab group and the first unpinned tab is grouped: // move the tab group right before the first unpinned tab's tab group. @@ -744,7 +744,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 element.pinned ? this.tabContainer.pinnedTabsContainer : this.tabContainer; -@@ -6417,7 +6593,7 @@ +@@ -6508,7 +6684,7 @@ element, () => { if (moveBefore) { @@ -753,7 +753,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 } else if (targetElement) { targetElement.after(element); } else { -@@ -6489,10 +6665,10 @@ +@@ -6580,10 +6756,10 @@ * @param {TabMetricsContext} [metricsContext] */ moveTabToGroup(aTab, aGroup, metricsContext) { @@ -766,7 +766,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6522,6 +6698,7 @@ +@@ -6613,6 +6789,7 @@ let state = { tabIndex: tab._tPos, @@ -774,7 +774,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 }; if (tab.visible) { state.elementIndex = tab.elementIndex; -@@ -6548,7 +6725,7 @@ +@@ -6639,7 +6816,7 @@ let changedTabGroup = previousTabState.tabGroupId != currentTabState.tabGroupId; @@ -783,7 +783,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 tab.dispatchEvent( new CustomEvent("TabMove", { bubbles: true, -@@ -6585,6 +6762,10 @@ +@@ -6676,6 +6853,10 @@ moveActionCallback(); @@ -794,7 +794,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7486,7 +7667,7 @@ +@@ -7576,7 +7757,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -803,7 +803,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 window.focus(); aEvent.preventDefault(); break; -@@ -7501,7 +7682,6 @@ +@@ -7593,7 +7774,6 @@ } case "TabGroupCollapse": aEvent.target.tabs.forEach(tab => { @@ -811,7 +811,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 }); break; case "TabGroupCreateByUser": -@@ -8442,6 +8622,7 @@ +@@ -8542,6 +8722,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -819,7 +819,7 @@ index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -9443,7 +9624,7 @@ var TabContextMenu = { +@@ -9543,7 +9724,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; From e5517eb1642bd3c9170373a65754232c1360015b Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Thu, 13 Nov 2025 13:57:32 +0100 Subject: [PATCH 11/18] Discard changes to src/browser/components/sessionstore/SessionStore-sys-mjs.patch --- .../sessionstore/SessionStore-sys-mjs.patch | 59 +++++++------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index 7c625f2af..79c5bcfcf 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,25 +1,17 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be523e4feb 100644 +index eb62ff3e733e43fdaa299babddea3ba0125abb06..8f20ba50b06f5b75d7de08eb4d1b27d89fb95494 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs -@@ -127,6 +127,8 @@ const TAB_EVENTS = [ +@@ -126,6 +126,8 @@ const TAB_EVENTS = [ + "TabUngrouped", "TabGroupCollapse", "TabGroupExpand", - "TabSplitViewActivate", + "TabAddedToEssentials", + "TabRemovedFromEssentials", ]; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -@@ -196,6 +198,7 @@ ChromeUtils.defineESModuleGetters(lazy, { - TabStateCache: "resource:///modules/sessionstore/TabStateCache.sys.mjs", - TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.sys.mjs", - setTimeout: "resource://gre/modules/Timer.sys.mjs", -+ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", - }); - - ChromeUtils.defineLazyGetter(lazy, "blankURI", () => { -@@ -1911,6 +1914,8 @@ var SessionStoreInternal = { +@@ -1904,6 +1906,8 @@ var SessionStoreInternal = { case "TabPinned": case "TabUnpinned": case "SwapDocShells": @@ -28,7 +20,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2151,7 +2156,6 @@ var SessionStoreInternal = { +@@ -2139,7 +2143,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -36,18 +28,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2215,6 +2219,10 @@ var SessionStoreInternal = { - }); - this._shouldRestoreLastSession = false; - } -+ else if (!aInitialState && isRegularWindow) { -+ aInitialState = lazy.ZenSessionStore.getNewWindowData(this._windows); -+ this.restoreWindows(aWindow, aInitialState, {}); -+ } - - if (this._restoreLastWindow && aWindow.toolbar.visible) { - // always reset (if not a popup window) -@@ -2384,11 +2392,9 @@ var SessionStoreInternal = { +@@ -2372,11 +2375,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } @@ -59,7 +40,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be // Store the window's close date to figure out when each individual tab // was closed. This timestamp should allow re-arranging data based on how -@@ -3373,7 +3379,7 @@ var SessionStoreInternal = { +@@ -3361,7 +3362,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -68,7 +49,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be return; } -@@ -4089,6 +4095,11 @@ var SessionStoreInternal = { +@@ -4073,6 +4074,11 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -80,7 +61,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4525,6 +4536,7 @@ var SessionStoreInternal = { +@@ -4509,6 +4515,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -88,7 +69,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5374,7 +5386,7 @@ var SessionStoreInternal = { +@@ -5358,7 +5365,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -97,7 +78,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be removableTabs.push(tab); } } -@@ -5434,7 +5446,7 @@ var SessionStoreInternal = { +@@ -5418,7 +5425,7 @@ var SessionStoreInternal = { } let workspaceID = aWindow.getWorkspaceID(); @@ -106,7 +87,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be winData.workspaceID = workspaceID; } }, -@@ -5625,11 +5637,12 @@ var SessionStoreInternal = { +@@ -5609,11 +5616,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -120,7 +101,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5640,6 +5653,7 @@ var SessionStoreInternal = { +@@ -5624,6 +5632,7 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -128,7 +109,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5652,7 +5666,7 @@ var SessionStoreInternal = { +@@ -5636,7 +5645,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -137,7 +118,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5764,8 +5778,8 @@ var SessionStoreInternal = { +@@ -5748,8 +5757,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -148,7 +129,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5808,6 +5822,8 @@ var SessionStoreInternal = { +@@ -5792,6 +5801,8 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -157,7 +138,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6371,6 +6387,25 @@ var SessionStoreInternal = { +@@ -6348,6 +6359,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -171,8 +152,8 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenSyncId) { -+ tab.setAttribute("zen-sync-id", tabData.zenSyncId); ++ if (tabData.zenPinnedId) { ++ tab.setAttribute("zen-pin-id", tabData.zenPinnedId); + } + if (tabData.zenDefaultUserContextId) { + tab.setAttribute("zenDefaultUserContextId", true); @@ -183,7 +164,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..2a7d429e2ed2f2be5bb554a5fb5fd2be if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7289,7 +7324,7 @@ var SessionStoreInternal = { +@@ -7263,7 +7293,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { From 3e39ef2538fef944a4fa21e8610e07c2ba74d9e6 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Thu, 13 Nov 2025 13:57:42 +0100 Subject: [PATCH 12/18] Discard changes to src/browser/components/tabbrowser/content/tab-js.patch --- .../tabbrowser/content/tab-js.patch | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/browser/components/tabbrowser/content/tab-js.patch b/src/browser/components/tabbrowser/content/tab-js.patch index 75153b173..997098854 100644 --- a/src/browser/components/tabbrowser/content/tab-js.patch +++ b/src/browser/components/tabbrowser/content/tab-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tab.js b/browser/components/tabbrowser/content/tab.js -index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577b5fad08c 100644 +index 425aaf8c8e4adf1507eb0d8ded671f8295544b04..12988986c4cf00990c1d1b2e4be362efc001afdd 100644 --- a/browser/components/tabbrowser/content/tab.js +++ b/browser/components/tabbrowser/content/tab.js @@ -21,6 +21,7 @@ @@ -42,7 +42,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 ".tab-label-container": "pinned,selected=visuallyselected,labeldirection", ".tab-label": -@@ -186,7 +189,7 @@ +@@ -184,7 +187,7 @@ } set _visuallySelected(val) { @@ -51,7 +51,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 return; } -@@ -222,11 +225,21 @@ +@@ -220,11 +223,21 @@ } get visible() { @@ -78,7 +78,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 } get hidden() { -@@ -297,7 +310,7 @@ +@@ -295,7 +308,7 @@ return false; } @@ -87,7 +87,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 } get lastAccessed() { -@@ -374,8 +387,11 @@ +@@ -372,8 +385,11 @@ } get group() { @@ -101,7 +101,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 } return null; } -@@ -470,6 +486,8 @@ +@@ -468,6 +484,8 @@ this.style.MozUserFocus = "ignore"; } else if ( event.target.classList.contains("tab-close-button") || @@ -110,7 +110,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 event.target.classList.contains("tab-icon-overlay") || event.target.classList.contains("tab-audio-button") ) { -@@ -524,6 +542,10 @@ +@@ -522,6 +540,10 @@ this.style.MozUserFocus = ""; } @@ -121,7 +121,15 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 on_click(event) { if (event.button != 0) { return; -@@ -584,6 +607,14 @@ +@@ -570,6 +592,7 @@ + ) + ); + } else { ++ gZenPinnedTabManager._removePinnedAttributes(this, true); + gBrowser.removeTab(this, { + animate: true, + triggeringEvent: event, +@@ -582,6 +605,14 @@ // (see tabbrowser-tabs 'click' handler). gBrowser.tabContainer._blockDblClick = true; } @@ -136,7 +144,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 } on_dblclick(event) { -@@ -607,6 +638,8 @@ +@@ -605,6 +636,8 @@ animate: true, triggeringEvent: event, }); From 7f225ac3eea3f205f4c47fc2c73c0dd5e3a31919 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Thu, 13 Nov 2025 13:57:55 +0100 Subject: [PATCH 13/18] Discard changes to src/browser/components/tabbrowser/content/tabbrowser-js.patch --- .../tabbrowser/content/tabbrowser-js.patch | 152 ++++++++++-------- 1 file changed, 85 insertions(+), 67 deletions(-) diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index 2b2a58d5d..11561149a 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,8 +1,8 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc349868d0d0 100644 +index c099e8646b9341a3ff55bf394037c8fc2769969b..0d524a0519bbbdf304a594d1fb56c394b7dbc6a7 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js -@@ -450,15 +450,64 @@ +@@ -432,15 +432,64 @@ return this.tabContainer.visibleTabs; } @@ -69,7 +69,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 set selectedTab(val) { if ( gSharedTabWarning.willShowSharedTabWarning(val) || -@@ -613,6 +662,7 @@ +@@ -588,6 +637,7 @@ this.tabpanels.appendChild(panel); let tab = this.tabs[0]; @@ -77,7 +77,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 tab.linkedPanel = uniqueId; this._selectedTab = tab; this._selectedBrowser = browser; -@@ -898,13 +948,17 @@ +@@ -873,13 +923,17 @@ } this.showTab(aTab); @@ -96,7 +96,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 aTab.setAttribute("pinned", "true"); this._updateTabBarForPinnedTabs(); -@@ -917,11 +971,15 @@ +@@ -892,11 +946,15 @@ } this.#handleTabMove(aTab, () => { @@ -113,7 +113,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 }); aTab.style.marginInlineStart = ""; -@@ -1098,6 +1156,8 @@ +@@ -1073,6 +1131,8 @@ let LOCAL_PROTOCOLS = ["chrome:", "about:", "resource:", "data:"]; @@ -122,7 +122,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if ( aIconURL && !LOCAL_PROTOCOLS.some(protocol => aIconURL.startsWith(protocol)) -@@ -1107,6 +1167,9 @@ +@@ -1082,6 +1142,9 @@ ); return; } @@ -132,7 +132,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 let browser = this.getBrowserForTab(aTab); browser.mIconURL = aIconURL; -@@ -1470,6 +1533,7 @@ +@@ -1445,6 +1508,7 @@ if (!this._previewMode) { newTab.recordTimeFromUnloadToReload(); newTab.updateLastAccessed(); @@ -140,7 +140,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 oldTab.updateLastAccessed(); // if this is the foreground window, update the last-seen timestamps. if (this.ownerGlobal == BrowserWindowTracker.getTopWindow()) { -@@ -1622,6 +1686,9 @@ +@@ -1597,6 +1661,9 @@ } let activeEl = document.activeElement; @@ -150,7 +150,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // If focus is on the old tab, move it to the new tab. if (activeEl == oldTab) { newTab.focus(); -@@ -1945,7 +2012,8 @@ +@@ -1920,7 +1987,8 @@ } _setTabLabel(aTab, aLabel, { beforeTabOpen, isContentTitle, isURL } = {}) { @@ -160,7 +160,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 return false; } -@@ -2053,7 +2121,7 @@ +@@ -2028,7 +2096,7 @@ newIndex = this.selectedTab._tPos + 1; } @@ -169,7 +169,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (this.isTabGroupLabel(targetTab)) { throw new Error( "Replacing a tab group label with a tab is not supported" -@@ -2328,6 +2396,7 @@ +@@ -2303,6 +2371,7 @@ uriIsAboutBlank, userContextId, skipLoad, @@ -177,7 +177,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } = {}) { let b = document.createXULElement("browser"); // Use the JSM global to create the permanentKey, so that if the -@@ -2401,8 +2470,7 @@ +@@ -2376,8 +2445,7 @@ // we use a different attribute name for this? b.setAttribute("name", name); } @@ -187,7 +187,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 b.setAttribute("transparent", "true"); } -@@ -2567,7 +2635,7 @@ +@@ -2542,7 +2610,7 @@ let panel = this.getPanel(browser); let uniqueId = this._generateUniquePanelID(); @@ -196,7 +196,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 aTab.linkedPanel = uniqueId; // Inject the into the DOM if necessary. -@@ -2626,8 +2694,8 @@ +@@ -2601,8 +2669,8 @@ // If we transitioned from one browser to two browsers, we need to set // hasSiblings=false on both the existing browser and the new browser. if (this.tabs.length == 2) { @@ -207,7 +207,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else { aTab.linkedBrowser.browsingContext.hasSiblings = this.tabs.length > 1; } -@@ -2814,7 +2882,6 @@ +@@ -2779,7 +2847,6 @@ this.selectedTab = this.addTrustedTab(BROWSER_NEW_TAB_URL, { tabIndex: tab._tPos + 1, userContextId: tab.userContextId, @@ -215,7 +215,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 focusUrlBar: true, }); resolve(this.selectedBrowser); -@@ -2923,6 +2990,8 @@ +@@ -2859,6 +2926,8 @@ schemelessInput, hasValidUserGestureActivation = false, textDirectiveUserActivation = false, @@ -224,7 +224,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } = {} ) { // all callers of addTab that pass a params object need to pass -@@ -2933,6 +3002,12 @@ +@@ -2869,6 +2938,12 @@ ); } @@ -237,7 +237,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (!UserInteraction.running("browser.tabs.opening", window)) { UserInteraction.start("browser.tabs.opening", "initting", window); } -@@ -2996,6 +3071,19 @@ +@@ -2932,6 +3007,19 @@ noInitialLabel, skipBackgroundNotify, }); @@ -257,7 +257,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (insertTab) { // Insert the tab into the tab container in the correct position. this.#insertTabAtIndex(t, { -@@ -3004,6 +3092,7 @@ +@@ -2940,6 +3028,7 @@ ownerTab, openerTab, pinned, @@ -265,7 +265,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 bulkOrderedOpen, tabGroup: tabGroup ?? openerTab?.group, }); -@@ -3022,6 +3111,7 @@ +@@ -2958,6 +3047,7 @@ openWindowInfo, skipLoad, triggeringRemoteType, @@ -273,7 +273,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 })); if (focusUrlBar) { -@@ -3146,6 +3236,12 @@ +@@ -3078,6 +3168,12 @@ } } @@ -286,7 +286,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // Additionally send pinned tab events if (pinned) { this.#notifyPinnedStatus(t); -@@ -3330,10 +3426,10 @@ +@@ -3248,10 +3344,10 @@ isAdoptingGroup = false, isUserTriggered = false, telemetryUserCreateSource = "unknown", @@ -298,7 +298,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } if (!color) { -@@ -3354,9 +3450,14 @@ +@@ -3272,9 +3368,14 @@ label, isAdoptingGroup ); @@ -315,7 +315,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 ); group.addTabs(tabs); -@@ -3477,7 +3578,7 @@ +@@ -3395,7 +3496,7 @@ } this.#handleTabMove(tab, () => @@ -324,7 +324,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 ); } -@@ -3679,6 +3780,7 @@ +@@ -3597,6 +3698,7 @@ openWindowInfo, skipLoad, triggeringRemoteType, @@ -332,7 +332,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } ) { // If we don't have a preferred remote type (or it is `NOT_REMOTE`), and -@@ -3748,6 +3850,7 @@ +@@ -3666,6 +3768,7 @@ openWindowInfo, name, skipLoad, @@ -340,7 +340,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 }); } -@@ -3935,7 +4038,7 @@ +@@ -3853,7 +3956,7 @@ // Add a new tab if needed. if (!tab) { let createLazyBrowser = @@ -349,7 +349,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 let url = "about:blank"; if (tabData.entries?.length) { -@@ -3972,8 +4075,10 @@ +@@ -3890,8 +3993,10 @@ insertTab: false, skipLoad: true, preferredRemoteType, @@ -361,7 +361,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (select) { tabToSelect = tab; } -@@ -3985,7 +4090,8 @@ +@@ -3903,7 +4008,8 @@ this.pinTab(tab); // Then ensure all the tab open/pinning information is sent. this._fireTabOpen(tab, {}); @@ -371,7 +371,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 let { groupId } = tabData; const tabGroup = tabGroupWorkingData.get(groupId); // if a tab refers to a tab group we don't know, skip any group -@@ -3999,7 +4105,10 @@ +@@ -3917,7 +4023,10 @@ tabGroup.stateData.id, tabGroup.stateData.color, tabGroup.stateData.collapsed, @@ -383,7 +383,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 ); tabsFragment.appendChild(tabGroup.node); } -@@ -4044,9 +4153,23 @@ +@@ -3962,9 +4071,23 @@ // to remove the old selected tab. if (tabToSelect) { let leftoverTab = this.selectedTab; @@ -407,7 +407,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (tabs.length > 1 || !tabs[0].selected) { this._updateTabsAfterInsert(); -@@ -4237,11 +4360,14 @@ +@@ -4155,11 +4278,14 @@ if (ownerTab) { tab.owner = ownerTab; } @@ -423,7 +423,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if ( !bulkOrderedOpen && ((openerTab && -@@ -4253,7 +4379,7 @@ +@@ -4171,7 +4297,7 @@ let lastRelatedTab = openerTab && this._lastRelatedTabMap.get(openerTab); let previousTab = lastRelatedTab || openerTab || this.selectedTab; @@ -432,7 +432,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 tabGroup = previousTab.group; } if ( -@@ -4264,7 +4390,7 @@ +@@ -4182,7 +4308,7 @@ ) { elementIndex = Infinity; } else if (previousTab.visible) { @@ -441,7 +441,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else if (previousTab == FirefoxViewHandler.tab) { elementIndex = 0; } -@@ -4292,14 +4418,14 @@ +@@ -4210,14 +4336,14 @@ } // Ensure index is within bounds. if (tab.pinned) { @@ -460,7 +460,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (pinned && !itemAfter?.pinned) { itemAfter = null; -@@ -4310,7 +4436,7 @@ +@@ -4228,7 +4354,7 @@ this.tabContainer._invalidateCachedTabs(); @@ -469,7 +469,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (this.isTab(itemAfter) && itemAfter.group == tabGroup) { // Place at the front of, or between tabs in, the same tab group this.tabContainer.insertBefore(tab, itemAfter); -@@ -4346,6 +4472,7 @@ +@@ -4264,6 +4390,7 @@ if (pinned) { this._updateTabBarForPinnedTabs(); } @@ -477,7 +477,17 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 TabBarVisibility.update(); } -@@ -4896,6 +5026,7 @@ +@@ -4553,6 +4680,9 @@ + return; + } + ++ for (let tab of selectedTabs) { ++ gZenPinnedTabManager._removePinnedAttributes(tab, true); ++ } + this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource }); + } + +@@ -4814,6 +4944,7 @@ telemetrySource, } = {} ) { @@ -485,7 +495,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4985,6 +5116,7 @@ +@@ -4903,6 +5034,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -493,7 +503,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } catch (e) { console.error(e); } -@@ -5023,6 +5155,12 @@ +@@ -4941,6 +5073,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -506,7 +516,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -5037,6 +5175,9 @@ +@@ -4955,6 +5093,9 @@ // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; let isLastTab = this.#isLastTabInWindow(aTab); @@ -516,7 +526,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -5085,7 +5226,13 @@ +@@ -5003,7 +5144,13 @@ // We're not animating, so we can cancel the animation stopwatch. Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId); aTab._closeTimeAnimTimerId = null; @@ -531,7 +541,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 return; } -@@ -5219,7 +5366,7 @@ +@@ -5137,7 +5284,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -540,7 +550,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -5243,6 +5390,7 @@ +@@ -5161,6 +5308,7 @@ newTab = true; } @@ -548,7 +558,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -5283,13 +5431,7 @@ +@@ -5201,13 +5349,7 @@ aTab._mouseleave(); if (newTab) { @@ -563,7 +573,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else { TabBarVisibility.update(); } -@@ -5422,6 +5564,7 @@ +@@ -5340,6 +5482,7 @@ this.tabs[i]._tPos = i; } @@ -571,7 +581,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (!this._windowIsClosing) { // update tab close buttons state this.tabContainer._updateCloseButtons(); -@@ -5643,6 +5786,7 @@ +@@ -5552,6 +5695,7 @@ } let excludeTabs = new Set(aExcludeTabs); @@ -579,7 +589,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // If this tab has a successor, it should be selectable, since // hiding or closing a tab removes that tab as a successor. -@@ -5655,13 +5799,13 @@ +@@ -5564,13 +5708,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -595,7 +605,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5677,7 +5821,7 @@ +@@ -5586,7 +5730,7 @@ } if (tab) { @@ -604,7 +614,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } // If no qualifying visible tab was found, see if there is a tab in -@@ -5698,7 +5842,7 @@ +@@ -5607,7 +5751,7 @@ }); } @@ -613,7 +623,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } _blurTab(aTab) { -@@ -6104,10 +6248,10 @@ +@@ -6013,10 +6157,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -626,7 +636,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6166,6 +6310,7 @@ +@@ -6075,6 +6219,7 @@ * @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab */ replaceTabWithWindow(aTab, aOptions) { @@ -634,7 +644,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (this.tabs.length == 1) { return null; } -@@ -6299,7 +6444,7 @@ +@@ -6208,7 +6353,7 @@ * `true` if element is a `` */ isTabGroup(element) { @@ -643,7 +653,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } /** -@@ -6375,8 +6520,8 @@ +@@ -6284,8 +6429,8 @@ } // Don't allow mixing pinned and unpinned tabs. @@ -654,7 +664,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6402,10 +6547,16 @@ +@@ -6311,10 +6456,16 @@ this.#handleTabMove( element, () => { @@ -673,7 +683,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6463,23 +6614,28 @@ +@@ -6372,23 +6523,28 @@ #moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) { if (this.isTabGroupLabel(targetElement)) { targetElement = targetElement.group; @@ -708,7 +718,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else if (!element.pinned && targetElement && targetElement.pinned) { // If the caller asks to move an unpinned element next to a pinned // tab, move the unpinned element to be the first unpinned element -@@ -6492,14 +6648,34 @@ +@@ -6401,14 +6557,34 @@ // move the tab group right before the first unpinned tab. // 4. Moving a tab group and the first unpinned tab is grouped: // move the tab group right before the first unpinned tab's tab group. @@ -744,7 +754,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 element.pinned ? this.tabContainer.pinnedTabsContainer : this.tabContainer; -@@ -6508,7 +6684,7 @@ +@@ -6417,7 +6593,7 @@ element, () => { if (moveBefore) { @@ -753,7 +763,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 } else if (targetElement) { targetElement.after(element); } else { -@@ -6580,10 +6756,10 @@ +@@ -6489,10 +6665,10 @@ * @param {TabMetricsContext} [metricsContext] */ moveTabToGroup(aTab, aGroup, metricsContext) { @@ -766,7 +776,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6613,6 +6789,7 @@ +@@ -6522,6 +6698,7 @@ let state = { tabIndex: tab._tPos, @@ -774,7 +784,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 }; if (tab.visible) { state.elementIndex = tab.elementIndex; -@@ -6639,7 +6816,7 @@ +@@ -6548,7 +6725,7 @@ let changedTabGroup = previousTabState.tabGroupId != currentTabState.tabGroupId; @@ -783,7 +793,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 tab.dispatchEvent( new CustomEvent("TabMove", { bubbles: true, -@@ -6676,6 +6853,10 @@ +@@ -6585,6 +6762,10 @@ moveActionCallback(); @@ -794,7 +804,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7576,7 +7757,7 @@ +@@ -7486,7 +7667,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -803,7 +813,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 window.focus(); aEvent.preventDefault(); break; -@@ -7593,7 +7774,6 @@ +@@ -7501,7 +7682,6 @@ } case "TabGroupCollapse": aEvent.target.tabs.forEach(tab => { @@ -811,7 +821,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 }); break; case "TabGroupCreateByUser": -@@ -8542,6 +8722,7 @@ +@@ -8442,6 +8622,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -819,7 +829,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -9543,7 +9724,7 @@ var TabContextMenu = { +@@ -9443,7 +9624,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -828,3 +838,11 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..326bf96d9346aba7096d518fbf63cc34 // Build Ask Chat items TabContextMenu.GenAI.buildTabMenu( document.getElementById("context_askChat"), +@@ -9763,6 +9944,7 @@ var TabContextMenu = { + ) + ); + } else { ++ gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true); + gBrowser.removeTab(this.contextTab, { + animate: true, + ...gBrowser.TabMetrics.userTriggeredContext( From 68b37ac73642566c31e5053b2896c0bc781e0bd5 Mon Sep 17 00:00:00 2001 From: "mr. m" <91018726+mr-cheffy@users.noreply.github.com> Date: Thu, 13 Nov 2025 13:58:18 +0100 Subject: [PATCH 14/18] Discard changes to src/zen/tabs/ZenPinnedTabsStorage.mjs --- src/zen/tabs/ZenPinnedTabsStorage.mjs | 635 ++++++++++++++++++++++++++ 1 file changed, 635 insertions(+) create mode 100644 src/zen/tabs/ZenPinnedTabsStorage.mjs diff --git a/src/zen/tabs/ZenPinnedTabsStorage.mjs b/src/zen/tabs/ZenPinnedTabsStorage.mjs new file mode 100644 index 000000000..425dbf2d1 --- /dev/null +++ b/src/zen/tabs/ZenPinnedTabsStorage.mjs @@ -0,0 +1,635 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. +var ZenPinnedTabsStorage = { + async init() { + await this._ensureTable(); + }, + + async _ensureTable() { + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage._ensureTable', async (db) => { + // Create the pins table if it doesn't exist + await db.execute(` + CREATE TABLE IF NOT EXISTS zen_pins ( + id INTEGER PRIMARY KEY, + uuid TEXT UNIQUE NOT NULL, + title TEXT NOT NULL, + url TEXT, + container_id INTEGER, + workspace_uuid TEXT, + position INTEGER NOT NULL DEFAULT 0, + is_essential BOOLEAN NOT NULL DEFAULT 0, + is_group BOOLEAN NOT NULL DEFAULT 0, + created_at INTEGER NOT NULL, + updated_at INTEGER NOT NULL + ) + `); + + const columns = await db.execute(`PRAGMA table_info(zen_pins)`); + const columnNames = columns.map((row) => row.getResultByName('name')); + + // Helper function to add column if it doesn't exist + const addColumnIfNotExists = async (columnName, definition) => { + if (!columnNames.includes(columnName)) { + await db.execute(`ALTER TABLE zen_pins ADD COLUMN ${columnName} ${definition}`); + } + }; + + await addColumnIfNotExists('edited_title', 'BOOLEAN NOT NULL DEFAULT 0'); + await addColumnIfNotExists('is_folder_collapsed', 'BOOLEAN NOT NULL DEFAULT 0'); + await addColumnIfNotExists('folder_icon', 'TEXT DEFAULT NULL'); + await addColumnIfNotExists('folder_parent_uuid', 'TEXT DEFAULT NULL'); + + await db.execute(` + CREATE INDEX IF NOT EXISTS idx_zen_pins_uuid ON zen_pins(uuid) + `); + + await db.execute(` + CREATE TABLE IF NOT EXISTS zen_pins_changes ( + uuid TEXT PRIMARY KEY, + timestamp INTEGER NOT NULL + ) + `); + + await db.execute(` + CREATE INDEX IF NOT EXISTS idx_zen_pins_changes_uuid ON zen_pins_changes(uuid) + `); + + this._resolveInitialized(); + }); + }, + + /** + * Private helper method to notify observers with a list of changed UUIDs. + * @param {string} event - The observer event name. + * @param {Array} uuids - Array of changed workspace UUIDs. + */ + _notifyPinsChanged(event, uuids) { + if (uuids.length === 0) return; // No changes to notify + + // Convert the array of UUIDs to a JSON string + const data = JSON.stringify(uuids); + + Services.obs.notifyObservers(null, event, data); + }, + + async savePin(pin, notifyObservers = true) { + const changedUUIDs = new Set(); + + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.savePin', async (db) => { + await db.executeTransaction(async () => { + const now = Date.now(); + + let newPosition; + if ('position' in pin && Number.isFinite(pin.position)) { + newPosition = pin.position; + } else { + // Get the maximum position within the same parent group (or null for root level) + const maxPositionResult = await db.execute( + ` + SELECT MAX("position") as max_position + FROM zen_pins + WHERE COALESCE(folder_parent_uuid, '') = COALESCE(:folder_parent_uuid, '') + `, + { folder_parent_uuid: pin.parentUuid || null } + ); + const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; + newPosition = maxPosition + 1000; + } + + // Insert or replace the pin + await db.executeCached( + ` + INSERT OR REPLACE INTO zen_pins ( + uuid, title, url, container_id, workspace_uuid, position, + is_essential, is_group, folder_parent_uuid, edited_title, created_at, + updated_at, is_folder_collapsed, folder_icon + ) VALUES ( + :uuid, :title, :url, :container_id, :workspace_uuid, :position, + :is_essential, :is_group, :folder_parent_uuid, :edited_title, + COALESCE((SELECT created_at FROM zen_pins WHERE uuid = :uuid), :now), + :now, :is_folder_collapsed, :folder_icon + ) + `, + { + uuid: pin.uuid, + title: pin.title, + url: pin.isGroup ? '' : pin.url, + container_id: pin.containerTabId || null, + workspace_uuid: pin.workspaceUuid || null, + position: newPosition, + is_essential: pin.isEssential || false, + is_group: pin.isGroup || false, + folder_parent_uuid: pin.parentUuid || null, + edited_title: pin.editedTitle || false, + now, + folder_icon: pin.folderIcon || null, + is_folder_collapsed: pin.isFolderCollapsed || false, + } + ); + + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid: pin.uuid, + timestamp: Math.floor(now / 1000), + } + ); + + changedUUIDs.add(pin.uuid); + await this.updateLastChangeTimestamp(db); + }); + }); + + if (notifyObservers) { + this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); + } + }, + + async getPins() { + const db = await PlacesUtils.promiseDBConnection(); + const rows = await db.executeCached(` + SELECT * FROM zen_pins + ORDER BY position ASC + `); + return rows.map((row) => ({ + uuid: row.getResultByName('uuid'), + title: row.getResultByName('title'), + url: row.getResultByName('url'), + containerTabId: row.getResultByName('container_id'), + workspaceUuid: row.getResultByName('workspace_uuid'), + position: row.getResultByName('position'), + isEssential: Boolean(row.getResultByName('is_essential')), + isGroup: Boolean(row.getResultByName('is_group')), + parentUuid: row.getResultByName('folder_parent_uuid'), + editedTitle: Boolean(row.getResultByName('edited_title')), + folderIcon: row.getResultByName('folder_icon'), + isFolderCollapsed: Boolean(row.getResultByName('is_folder_collapsed')), + })); + }, + + /** + * Create a new group + * @param {string} title - The title of the group + * @param {string} workspaceUuid - The workspace UUID (optional) + * @param {string} parentUuid - The parent group UUID (optional, null for root level) + * @param {number} position - The position of the group (optional, will auto-calculate if not provided) + * @param {boolean} notifyObservers - Whether to notify observers (default: true) + * @returns {Promise} The UUID of the created group + */ + async createGroup( + title, + icon = null, + isCollapsed = false, + workspaceUuid = null, + parentUuid = null, + position = null, + notifyObservers = true + ) { + if (!title || typeof title !== 'string') { + throw new Error('Group title is required and must be a string'); + } + + const groupUuid = gZenUIManager.generateUuidv4(); + + const groupPin = { + uuid: groupUuid, + title, + folderIcon: icon || null, + isFolderCollapsed: isCollapsed || false, + workspaceUuid, + parentUuid, + position, + isGroup: true, + isEssential: false, + editedTitle: true, // Group titles are always considered edited + }; + + await this.savePin(groupPin, notifyObservers); + return groupUuid; + }, + + /** + * Add an existing tab/pin to a group + * @param {string} tabUuid - The UUID of the tab to add to the group + * @param {string} groupUuid - The UUID of the target group + * @param {number} position - The position within the group (optional, will append if not provided) + * @param {boolean} notifyObservers - Whether to notify observers (default: true) + */ + async addTabToGroup(tabUuid, groupUuid, position = null, notifyObservers = true) { + if (!tabUuid || !groupUuid) { + throw new Error('Both tabUuid and groupUuid are required'); + } + + const changedUUIDs = new Set(); + + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.addTabToGroup', async (db) => { + await db.executeTransaction(async () => { + // Verify the group exists and is actually a group + const groupCheck = await db.execute( + `SELECT is_group FROM zen_pins WHERE uuid = :groupUuid`, + { groupUuid } + ); + + if (groupCheck.length === 0) { + throw new Error(`Group with UUID ${groupUuid} does not exist`); + } + + if (!groupCheck[0].getResultByName('is_group')) { + throw new Error(`Pin with UUID ${groupUuid} is not a group`); + } + + const tabCheck = await db.execute(`SELECT uuid FROM zen_pins WHERE uuid = :tabUuid`, { + tabUuid, + }); + + if (tabCheck.length === 0) { + throw new Error(`Tab with UUID ${tabUuid} does not exist`); + } + + const now = Date.now(); + let newPosition; + + if (position !== null && Number.isFinite(position)) { + newPosition = position; + } else { + // Get the maximum position within the group + const maxPositionResult = await db.execute( + `SELECT MAX("position") as max_position FROM zen_pins WHERE folder_parent_uuid = :groupUuid`, + { groupUuid } + ); + const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; + newPosition = maxPosition + 1000; + } + + await db.execute( + ` + UPDATE zen_pins + SET folder_parent_uuid = :groupUuid, + position = :newPosition, + updated_at = :now + WHERE uuid = :tabUuid + `, + { + tabUuid, + groupUuid, + newPosition, + now, + } + ); + + changedUUIDs.add(tabUuid); + + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid: tabUuid, + timestamp: Math.floor(now / 1000), + } + ); + + await this.updateLastChangeTimestamp(db); + }); + }); + + if (notifyObservers) { + this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); + } + }, + + /** + * Remove a tab from its group (move to root level) + * @param {string} tabUuid - The UUID of the tab to remove from its group + * @param {number} newPosition - The new position at root level (optional, will append if not provided) + * @param {boolean} notifyObservers - Whether to notify observers (default: true) + */ + async removeTabFromGroup(tabUuid, newPosition = null, notifyObservers = true) { + if (!tabUuid) { + throw new Error('tabUuid is required'); + } + + const changedUUIDs = new Set(); + + await PlacesUtils.withConnectionWrapper( + 'ZenPinnedTabsStorage.removeTabFromGroup', + async (db) => { + await db.executeTransaction(async () => { + // Verify the tab exists and is in a group + const tabCheck = await db.execute( + `SELECT folder_parent_uuid FROM zen_pins WHERE uuid = :tabUuid`, + { tabUuid } + ); + + if (tabCheck.length === 0) { + throw new Error(`Tab with UUID ${tabUuid} does not exist`); + } + + if (!tabCheck[0].getResultByName('folder_parent_uuid')) { + return; + } + + const now = Date.now(); + let finalPosition; + + if (newPosition !== null && Number.isFinite(newPosition)) { + finalPosition = newPosition; + } else { + // Get the maximum position at root level (where folder_parent_uuid is null) + const maxPositionResult = await db.execute( + `SELECT MAX("position") as max_position FROM zen_pins WHERE folder_parent_uuid IS NULL` + ); + const maxPosition = maxPositionResult[0].getResultByName('max_position') || 0; + finalPosition = maxPosition + 1000; + } + + // Update the tab to be at root level + await db.execute( + ` + UPDATE zen_pins + SET folder_parent_uuid = NULL, + position = :newPosition, + updated_at = :now + WHERE uuid = :tabUuid + `, + { + tabUuid, + newPosition: finalPosition, + now, + } + ); + + changedUUIDs.add(tabUuid); + + // Record the change + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid: tabUuid, + timestamp: Math.floor(now / 1000), + } + ); + + await this.updateLastChangeTimestamp(db); + }); + } + ); + + if (notifyObservers) { + this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); + } + }, + + async removePin(uuid, notifyObservers = true) { + const changedUUIDs = [uuid]; + + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.removePin', async (db) => { + await db.executeTransaction(async () => { + // Get all child UUIDs first for change tracking + const children = await db.execute( + `SELECT uuid FROM zen_pins WHERE folder_parent_uuid = :uuid`, + { + uuid, + } + ); + + // Add child UUIDs to changedUUIDs array + for (const child of children) { + changedUUIDs.push(child.getResultByName('uuid')); + } + + // Delete the pin/group itself + await db.execute(`DELETE FROM zen_pins WHERE uuid = :uuid`, { uuid }); + + // Record the changes + const now = Math.floor(Date.now() / 1000); + for (const changedUuid of changedUUIDs) { + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid: changedUuid, + timestamp: now, + } + ); + } + + await this.updateLastChangeTimestamp(db); + }); + }); + + if (notifyObservers) { + this._notifyPinsChanged('zen-pin-removed', changedUUIDs); + } + }, + + async wipeAllPins() { + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.wipeAllPins', async (db) => { + await db.execute(`DELETE FROM zen_pins`); + await db.execute(`DELETE FROM zen_pins_changes`); + await this.updateLastChangeTimestamp(db); + }); + }, + + async markChanged(uuid) { + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.markChanged', async (db) => { + const now = Date.now(); + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid, + timestamp: Math.floor(now / 1000), + } + ); + }); + }, + + async getChangedIDs() { + const db = await PlacesUtils.promiseDBConnection(); + const rows = await db.execute(` + SELECT uuid, timestamp FROM zen_pins_changes + `); + const changes = {}; + for (const row of rows) { + changes[row.getResultByName('uuid')] = row.getResultByName('timestamp'); + } + return changes; + }, + + async clearChangedIDs() { + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.clearChangedIDs', async (db) => { + await db.execute(`DELETE FROM zen_pins_changes`); + }); + }, + + shouldReorderPins(before, current, after) { + const minGap = 1; // Minimum allowed gap between positions + return ( + (before !== null && current - before < minGap) || (after !== null && after - current < minGap) + ); + }, + + async reorderAllPins(db, changedUUIDs) { + const pins = await db.execute(` + SELECT uuid + FROM zen_pins + ORDER BY position ASC + `); + + for (let i = 0; i < pins.length; i++) { + const newPosition = (i + 1) * 1000; // Use large increments + await db.execute( + ` + UPDATE zen_pins + SET position = :newPosition + WHERE uuid = :uuid + `, + { newPosition, uuid: pins[i].getResultByName('uuid') } + ); + changedUUIDs.add(pins[i].getResultByName('uuid')); + } + }, + + async updateLastChangeTimestamp(db) { + const now = Date.now(); + await db.execute( + ` + INSERT OR REPLACE INTO moz_meta (key, value) + VALUES ('zen_pins_last_change', :now) + `, + { now } + ); + }, + + async getLastChangeTimestamp() { + const db = await PlacesUtils.promiseDBConnection(); + const result = await db.executeCached(` + SELECT value FROM moz_meta WHERE key = 'zen_pins_last_change' + `); + return result.length ? parseInt(result[0].getResultByName('value'), 10) : 0; + }, + + async updatePinPositions(pins) { + const changedUUIDs = new Set(); + + await PlacesUtils.withConnectionWrapper( + 'ZenPinnedTabsStorage.updatePinPositions', + async (db) => { + await db.executeTransaction(async () => { + const now = Date.now(); + + for (let i = 0; i < pins.length; i++) { + const pin = pins[i]; + const newPosition = (i + 1) * 1000; + + await db.execute( + ` + UPDATE zen_pins + SET position = :newPosition + WHERE uuid = :uuid + `, + { newPosition, uuid: pin.uuid } + ); + + changedUUIDs.add(pin.uuid); + + // Record the change + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid: pin.uuid, + timestamp: Math.floor(now / 1000), + } + ); + } + + await this.updateLastChangeTimestamp(db); + }); + } + ); + + this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); + }, + + async updatePinTitle(uuid, newTitle, isEdited = true, notifyObservers = true) { + if (!uuid || typeof newTitle !== 'string') { + throw new Error('Invalid parameters: uuid and newTitle are required'); + } + + const changedUUIDs = new Set(); + + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.updatePinTitle', async (db) => { + await db.executeTransaction(async () => { + const now = Date.now(); + + // Update the pin's title and edited_title flag + const result = await db.execute( + ` + UPDATE zen_pins + SET title = :newTitle, + edited_title = :isEdited, + updated_at = :now + WHERE uuid = :uuid + `, + { + uuid, + newTitle, + isEdited, + now, + } + ); + + // Only proceed with change tracking if a row was actually updated + if (result.rowsAffected > 0) { + changedUUIDs.add(uuid); + + // Record the change + await db.execute( + ` + INSERT OR REPLACE INTO zen_pins_changes (uuid, timestamp) + VALUES (:uuid, :timestamp) + `, + { + uuid, + timestamp: Math.floor(now / 1000), + } + ); + + await this.updateLastChangeTimestamp(db); + } + }); + }); + + if (notifyObservers && changedUUIDs.size > 0) { + this._notifyPinsChanged('zen-pin-updated', Array.from(changedUUIDs)); + } + }, + + async __dropTables() { + await PlacesUtils.withConnectionWrapper('ZenPinnedTabsStorage.__dropTables', async (db) => { + await db.execute(`DROP TABLE IF EXISTS zen_pins`); + await db.execute(`DROP TABLE IF EXISTS zen_pins_changes`); + }); + }, +}; + +ZenPinnedTabsStorage.promiseInitialized = new Promise((resolve) => { + ZenPinnedTabsStorage._resolveInitialized = resolve; + ZenPinnedTabsStorage.init(); +}); From 12c921fd878393fe03a0b2f3549f09f407650ce2 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Thu, 13 Nov 2025 14:40:52 +0100 Subject: [PATCH 15/18] feat: Run session saver before opening a new winodw, b=no-bug, c=tabs --- .../sessionstore/SessionFile-sys-mjs.patch | 4 +- .../sessionstore/SessionStore-sys-mjs.patch | 55 +++++++++---- .../tabbrowser/content/tab-js.patch | 14 +--- .../tabbrowser/content/tabbrowser-js.patch | 82 ++++++++----------- .../sessionstore/ZenSessionManager.sys.mjs | 10 ++- src/zen/tabs/ZenPinnedTabManager.mjs | 1 - 6 files changed, 81 insertions(+), 85 deletions(-) diff --git a/src/browser/components/sessionstore/SessionFile-sys-mjs.patch b/src/browser/components/sessionstore/SessionFile-sys-mjs.patch index 04aa6f0ca..895c4313f 100644 --- a/src/browser/components/sessionstore/SessionFile-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionFile-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionFile.sys.mjs b/browser/components/sessionstore/SessionFile.sys.mjs -index 157c55ab24a418b56690d2e26320582909b919e4..14755f57dc450583e69eee94eb11f16980d5e5cb 100644 +index 31140cb8be3b529a0952ca8dc55165690b0e2120..605c9e0aa84da0a2d3171a0573e8cd95e27bd0c4 100644 --- a/browser/components/sessionstore/SessionFile.sys.mjs +++ b/browser/components/sessionstore/SessionFile.sys.mjs @@ -22,6 +22,7 @@ ChromeUtils.defineESModuleGetters(lazy, { @@ -10,7 +10,7 @@ index 157c55ab24a418b56690d2e26320582909b919e4..14755f57dc450583e69eee94eb11f169 }); const PREF_UPGRADE_BACKUP = "browser.sessionstore.upgradeBackup.latestBuildID"; -@@ -364,7 +365,7 @@ var SessionFileInternal = { +@@ -380,7 +381,7 @@ var SessionFileInternal = { this._readOrigin = result.origin; result.noFilesFound = noFilesFound; diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index df250c095..c778b4fd5 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10540eb659 100644 +index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc3315aa98 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -127,6 +127,8 @@ const TAB_EVENTS = [ @@ -11,7 +11,15 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 ]; const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"; -@@ -1911,6 +1913,8 @@ var SessionStoreInternal = { +@@ -196,6 +198,7 @@ ChromeUtils.defineESModuleGetters(lazy, { + TabStateCache: "resource:///modules/sessionstore/TabStateCache.sys.mjs", + TabStateFlusher: "resource:///modules/sessionstore/TabStateFlusher.sys.mjs", + setTimeout: "resource://gre/modules/Timer.sys.mjs", ++ ZenSessionStore: "resource:///modules/zen/ZenSessionManager.sys.mjs", + }); + + ChromeUtils.defineLazyGetter(lazy, "blankURI", () => { +@@ -1911,6 +1914,8 @@ var SessionStoreInternal = { case "TabPinned": case "TabUnpinned": case "SwapDocShells": @@ -20,7 +28,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 this.saveStateDelayed(win); break; case "TabGroupCreate": -@@ -2151,7 +2155,6 @@ var SessionStoreInternal = { +@@ -2151,7 +2156,6 @@ var SessionStoreInternal = { if (closedWindowState) { let newWindowState; if ( @@ -28,7 +36,18 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2384,11 +2387,9 @@ var SessionStoreInternal = { +@@ -2215,6 +2219,10 @@ var SessionStoreInternal = { + }); + this._shouldRestoreLastSession = false; + } ++ else if (!aInitialState && isRegularWindow) { ++ aInitialState = lazy.ZenSessionStore.getNewWindowData(); ++ this.restoreWindows(aWindow, aInitialState, {}); ++ } + + if (this._restoreLastWindow && aWindow.toolbar.visible) { + // always reset (if not a popup window) +@@ -2384,11 +2392,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } @@ -40,7 +59,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 // Store the window's close date to figure out when each individual tab // was closed. This timestamp should allow re-arranging data based on how -@@ -3373,7 +3374,7 @@ var SessionStoreInternal = { +@@ -3373,7 +3379,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -49,7 +68,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 return; } -@@ -4089,6 +4090,11 @@ var SessionStoreInternal = { +@@ -4089,6 +4095,11 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -61,7 +80,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4525,6 +4531,7 @@ var SessionStoreInternal = { +@@ -4525,6 +4536,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -69,7 +88,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5374,7 +5381,7 @@ var SessionStoreInternal = { +@@ -5374,7 +5386,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -78,7 +97,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 removableTabs.push(tab); } } -@@ -5434,7 +5441,7 @@ var SessionStoreInternal = { +@@ -5434,7 +5446,7 @@ var SessionStoreInternal = { } let workspaceID = aWindow.getWorkspaceID(); @@ -87,7 +106,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 winData.workspaceID = workspaceID; } }, -@@ -5625,11 +5632,12 @@ var SessionStoreInternal = { +@@ -5625,11 +5637,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -101,7 +120,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5640,6 +5648,7 @@ var SessionStoreInternal = { +@@ -5640,6 +5653,7 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -109,7 +128,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5652,7 +5661,7 @@ var SessionStoreInternal = { +@@ -5652,7 +5666,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -118,7 +137,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5764,8 +5773,8 @@ var SessionStoreInternal = { +@@ -5764,8 +5778,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -129,7 +148,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5808,6 +5817,8 @@ var SessionStoreInternal = { +@@ -5808,6 +5822,8 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -138,7 +157,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6371,6 +6382,25 @@ var SessionStoreInternal = { +@@ -6371,6 +6387,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -152,8 +171,8 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 + if (tabData.zenHasStaticLabel) { + tab.setAttribute("zen-has-static-label", "true"); + } -+ if (tabData.zenPinnedId) { -+ tab.setAttribute("zen-pin-id", tabData.zenPinnedId); ++ if (tabData.zenSyncId) { ++ tab.setAttribute("zen-sync-id", tabData.zenSyncId); + } + if (tabData.zenDefaultUserContextId) { + tab.setAttribute("zenDefaultUserContextId", true); @@ -164,7 +183,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..f13ed1412bb7ae6623aa2605d7691d10 if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7289,7 +7319,7 @@ var SessionStoreInternal = { +@@ -7289,7 +7324,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { diff --git a/src/browser/components/tabbrowser/content/tab-js.patch b/src/browser/components/tabbrowser/content/tab-js.patch index 3452bced0..fc652603c 100644 --- a/src/browser/components/tabbrowser/content/tab-js.patch +++ b/src/browser/components/tabbrowser/content/tab-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tab.js b/browser/components/tabbrowser/content/tab.js -index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577b5fad08c 100644 +index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..ce54ed0c8a93d5521a436c55c9432c090b0420ac 100644 --- a/browser/components/tabbrowser/content/tab.js +++ b/browser/components/tabbrowser/content/tab.js @@ -21,6 +21,7 @@ @@ -121,15 +121,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 on_click(event) { if (event.button != 0) { return; -@@ -572,6 +594,7 @@ - ) - ); - } else { -+ gZenPinnedTabManager._removePinnedAttributes(this, true); - gBrowser.removeTab(this, { - animate: true, - triggeringEvent: event, -@@ -584,6 +607,14 @@ +@@ -584,6 +606,14 @@ // (see tabbrowser-tabs 'click' handler). gBrowser.tabContainer._blockDblClick = true; } @@ -144,7 +136,7 @@ index 4c1a48424316b29d27ae2bc8b64004df41c87bb6..f1ff9bf0947127a8e9115357cedac577 } on_dblclick(event) { -@@ -607,6 +638,8 @@ +@@ -607,6 +637,8 @@ animate: true, triggeringEvent: event, }); diff --git a/src/browser/components/tabbrowser/content/tabbrowser-js.patch b/src/browser/components/tabbrowser/content/tabbrowser-js.patch index c581a6389..0582cbad4 100644 --- a/src/browser/components/tabbrowser/content/tabbrowser-js.patch +++ b/src/browser/components/tabbrowser/content/tabbrowser-js.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/tabbrowser/content/tabbrowser.js b/browser/components/tabbrowser/content/tabbrowser.js -index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad0c761fb5 100644 +index c0eafd4faf8d57b8486c5bf8917375850ec8147e..30c8fd7e978eb3036f35b17ae3f6ea4cd44d980e 100644 --- a/browser/components/tabbrowser/content/tabbrowser.js +++ b/browser/components/tabbrowser/content/tabbrowser.js @@ -450,15 +450,64 @@ @@ -420,10 +420,10 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad + gZenWorkspaces._initialTab._shouldRemove = true; + } + } - } ++ } + else { + gZenWorkspaces._tabToRemoveForEmpty = this.selectedTab; -+ } + } + this._hasAlreadyInitializedZenSessionStore = true; if (tabs.length > 1 || !tabs[0].selected) { @@ -498,17 +498,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad TabBarVisibility.update(); } -@@ -4635,6 +4763,9 @@ - return; - } - -+ for (let tab of selectedTabs) { -+ gZenPinnedTabManager._removePinnedAttributes(tab, true); -+ } - this.removeTabs(selectedTabs, { isUserTriggered, telemetrySource }); - } - -@@ -4896,6 +5027,7 @@ +@@ -4896,6 +5024,7 @@ telemetrySource, } = {} ) { @@ -516,7 +506,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad // When 'closeWindowWithLastTab' pref is enabled, closing all tabs // can be considered equivalent to closing the window. if ( -@@ -4985,6 +5117,7 @@ +@@ -4985,6 +5114,7 @@ if (lastToClose) { this.removeTab(lastToClose, aParams); } @@ -524,7 +514,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } catch (e) { console.error(e); } -@@ -5023,6 +5156,12 @@ +@@ -5023,6 +5153,12 @@ aTab._closeTimeNoAnimTimerId = Glean.browserTabclose.timeNoAnim.start(); } @@ -537,7 +527,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad // Handle requests for synchronously removing an already // asynchronously closing tab. if (!animate && aTab.closing) { -@@ -5037,6 +5176,9 @@ +@@ -5037,6 +5173,9 @@ // state). let tabWidth = window.windowUtils.getBoundsWithoutFlushing(aTab).width; let isLastTab = this.#isLastTabInWindow(aTab); @@ -547,7 +537,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad if ( !this._beginRemoveTab(aTab, { closeWindowFastpath: true, -@@ -5085,7 +5227,13 @@ +@@ -5085,7 +5224,13 @@ // We're not animating, so we can cancel the animation stopwatch. Glean.browserTabclose.timeAnim.cancel(aTab._closeTimeAnimTimerId); aTab._closeTimeAnimTimerId = null; @@ -562,7 +552,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad return; } -@@ -5219,7 +5367,7 @@ +@@ -5219,7 +5364,7 @@ closeWindowWithLastTab != null ? closeWindowWithLastTab : !window.toolbar.visible || @@ -571,7 +561,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad if (closeWindow) { // We've already called beforeunload on all the relevant tabs if we get here, -@@ -5243,6 +5391,7 @@ +@@ -5243,6 +5388,7 @@ newTab = true; } @@ -579,7 +569,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad aTab._endRemoveArgs = [closeWindow, newTab]; // swapBrowsersAndCloseOther will take care of closing the window without animation. -@@ -5283,13 +5432,7 @@ +@@ -5283,13 +5429,7 @@ aTab._mouseleave(); if (newTab) { @@ -594,7 +584,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } else { TabBarVisibility.update(); } -@@ -5422,6 +5565,7 @@ +@@ -5422,6 +5562,7 @@ this.tabs[i]._tPos = i; } @@ -602,7 +592,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad if (!this._windowIsClosing) { // update tab close buttons state this.tabContainer._updateCloseButtons(); -@@ -5643,6 +5787,7 @@ +@@ -5643,6 +5784,7 @@ } let excludeTabs = new Set(aExcludeTabs); @@ -610,7 +600,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad // If this tab has a successor, it should be selectable, since // hiding or closing a tab removes that tab as a successor. -@@ -5655,13 +5800,13 @@ +@@ -5655,13 +5797,13 @@ !excludeTabs.has(aTab.owner) && Services.prefs.getBoolPref("browser.tabs.selectOwnerOnClose") ) { @@ -626,7 +616,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad ); let tab = this.tabContainer.findNextTab(aTab, { -@@ -5677,7 +5822,7 @@ +@@ -5677,7 +5819,7 @@ } if (tab) { @@ -635,7 +625,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } // If no qualifying visible tab was found, see if there is a tab in -@@ -5698,7 +5843,7 @@ +@@ -5698,7 +5840,7 @@ }); } @@ -644,7 +634,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } _blurTab(aTab) { -@@ -6104,10 +6249,10 @@ +@@ -6104,10 +6246,10 @@ SessionStore.deleteCustomTabValue(aTab, "hiddenBy"); } @@ -657,7 +647,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad aTab.selected || aTab.closing || // Tabs that are sharing the screen, microphone or camera cannot be hidden. -@@ -6166,6 +6311,7 @@ +@@ -6166,6 +6308,7 @@ * @param {MozTabbrowserTab|MozTabbrowserTabGroup|MozTabbrowserTabGroup.labelElement} aTab */ replaceTabWithWindow(aTab, aOptions) { @@ -665,7 +655,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad if (this.tabs.length == 1) { return null; } -@@ -6299,7 +6445,7 @@ +@@ -6299,7 +6442,7 @@ * `true` if element is a `` */ isTabGroup(element) { @@ -674,7 +664,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } /** -@@ -6375,8 +6521,8 @@ +@@ -6375,8 +6518,8 @@ } // Don't allow mixing pinned and unpinned tabs. @@ -685,7 +675,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } else { tabIndex = Math.max(tabIndex, this.pinnedTabCount); } -@@ -6402,10 +6548,16 @@ +@@ -6402,10 +6545,16 @@ this.#handleTabMove( element, () => { @@ -704,7 +694,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad if (neighbor && this.isTab(element) && tabIndex > element._tPos) { neighbor.after(element); } else { -@@ -6463,23 +6615,28 @@ +@@ -6463,23 +6612,28 @@ #moveTabNextTo(element, targetElement, moveBefore = false, metricsContext) { if (this.isTabGroupLabel(targetElement)) { targetElement = targetElement.group; @@ -739,7 +729,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } else if (!element.pinned && targetElement && targetElement.pinned) { // If the caller asks to move an unpinned element next to a pinned // tab, move the unpinned element to be the first unpinned element -@@ -6492,14 +6649,34 @@ +@@ -6492,14 +6646,34 @@ // move the tab group right before the first unpinned tab. // 4. Moving a tab group and the first unpinned tab is grouped: // move the tab group right before the first unpinned tab's tab group. @@ -775,7 +765,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad element.pinned ? this.tabContainer.pinnedTabsContainer : this.tabContainer; -@@ -6508,7 +6685,7 @@ +@@ -6508,7 +6682,7 @@ element, () => { if (moveBefore) { @@ -784,7 +774,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad } else if (targetElement) { targetElement.after(element); } else { -@@ -6580,10 +6757,10 @@ +@@ -6580,10 +6754,10 @@ * @param {TabMetricsContext} [metricsContext] */ moveTabToGroup(aTab, aGroup, metricsContext) { @@ -797,7 +787,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad return; } if (aTab.group && aTab.group.id === aGroup.id) { -@@ -6613,6 +6790,7 @@ +@@ -6613,6 +6787,7 @@ let state = { tabIndex: tab._tPos, @@ -805,7 +795,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad }; if (tab.visible) { state.elementIndex = tab.elementIndex; -@@ -6639,7 +6817,7 @@ +@@ -6639,7 +6814,7 @@ let changedTabGroup = previousTabState.tabGroupId != currentTabState.tabGroupId; @@ -814,7 +804,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad tab.dispatchEvent( new CustomEvent("TabMove", { bubbles: true, -@@ -6676,6 +6854,10 @@ +@@ -6676,6 +6851,10 @@ moveActionCallback(); @@ -825,7 +815,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad // Clear tabs cache after moving nodes because the order of tabs may have // changed. this.tabContainer._invalidateCachedTabs(); -@@ -7576,7 +7758,7 @@ +@@ -7576,7 +7755,7 @@ // preventDefault(). It will still raise the window if appropriate. break; } @@ -834,7 +824,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad window.focus(); aEvent.preventDefault(); break; -@@ -7593,7 +7775,6 @@ +@@ -7593,7 +7772,6 @@ } case "TabGroupCollapse": aEvent.target.tabs.forEach(tab => { @@ -842,7 +832,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad }); break; case "TabGroupCreateByUser": -@@ -8542,6 +8723,7 @@ +@@ -8542,6 +8720,7 @@ aWebProgress.isTopLevel ) { this.mTab.setAttribute("busy", "true"); @@ -850,7 +840,7 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad gBrowser._tabAttrModified(this.mTab, ["busy"]); this.mTab._notselectedsinceload = !this.mTab.selected; } -@@ -9543,7 +9725,7 @@ var TabContextMenu = { +@@ -9543,7 +9722,7 @@ var TabContextMenu = { ); contextUnpinSelectedTabs.hidden = !this.contextTab.pinned || !this.multiselected; @@ -859,11 +849,3 @@ index c0eafd4faf8d57b8486c5bf8917375850ec8147e..2ab3908f421d6bc126eb7a0f886646ad // Build Ask Chat items TabContextMenu.GenAI.buildTabMenu( document.getElementById("context_askChat"), -@@ -9863,6 +10045,7 @@ var TabContextMenu = { - ) - ); - } else { -+ gZenPinnedTabManager._removePinnedAttributes(this.contextTab, true); - gBrowser.removeTab(this.contextTab, { - animate: true, - ...gBrowser.TabMetrics.userTriggeredContext( diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index e8cf59114..89ecc9bbb 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -10,6 +10,7 @@ ChromeUtils.defineESModuleGetters(lazy, { BrowserWindowTracker: 'resource:///modules/BrowserWindowTracker.sys.mjs', TabGroupState: 'resource:///modules/sessionstore/TabGroupState.sys.mjs', SessionStore: 'resource:///modules/sessionstore/SessionStore.sys.mjs', + SessionSaver: 'resource:///modules/sessionstore/SessionSaver.sys.mjs', }); const LAZY_COLLECT_THRESHOLD = 5 * 60 * 1000; // 5 minutes @@ -86,7 +87,7 @@ class nsZenSessionManager { if (lazy.PrivateBrowsingUtils.permanentPrivateBrowsing) { // Don't save (or even collect) anything in permanent private // browsing mode - return Promise.resolve(); + return; } // Collect an initial snapshot of window data before we do the flush. const window = this.#topMostWindow; @@ -154,8 +155,11 @@ class nsZenSessionManager { aWindowData.groups = sidebar.groups; } - getNewWindowData(aWindows) { - let newWindow = { ...Cu.cloneInto(aWindows[Object.keys(aWindows)[0]], {}), ...this.#sidebar }; + getNewWindowData() { + lazy.SessionSaver.run(); + const state = lazy.SessionStore.getCurrentState(forceUpdateAllWindows); + const windows = state.windows || {}; + let newWindow = { ...Cu.cloneInto(windows[Object.keys(windows)[0]], {}), ...this.#sidebar }; return { windows: [newWindow] }; } } diff --git a/src/zen/tabs/ZenPinnedTabManager.mjs b/src/zen/tabs/ZenPinnedTabManager.mjs index 245819a91..eb6be7034 100644 --- a/src/zen/tabs/ZenPinnedTabManager.mjs +++ b/src/zen/tabs/ZenPinnedTabManager.mjs @@ -232,7 +232,6 @@ switch (behavior) { case 'close': { for (const tab of pinnedTabs) { - this._removePinnedAttributes(tab, true); gBrowser.removeTab(tab, { animate: true }); } break; From eefc8cb20c51baad30e526a454893770b67ef149 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Thu, 13 Nov 2025 17:03:27 +0100 Subject: [PATCH 16/18] feat: Clone the previous state, b=no-bug, c=no-component --- src/zen/sessionstore/ZenSessionManager.sys.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 89ecc9bbb..2a229daca 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -157,9 +157,9 @@ class nsZenSessionManager { getNewWindowData() { lazy.SessionSaver.run(); - const state = lazy.SessionStore.getCurrentState(forceUpdateAllWindows); + const state = lazy.SessionStore.getCurrentState(true); const windows = state.windows || {}; - let newWindow = { ...Cu.cloneInto(windows[Object.keys(windows)[0]], {}), ...this.#sidebar }; + let newWindow = Cu.cloneInto(windows[0], {}); return { windows: [newWindow] }; } } From c86875b7b07703ad93176b55854fb0e853f2b6e2 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Mon, 17 Nov 2025 13:36:57 +0100 Subject: [PATCH 17/18] feat: Move window sync to its own JS module, b=no-bug, c=workspaces --- src/browser/base/content/zen-assets.inc.xhtml | 1 - .../base/content/zen-assets.jar.inc.mn | 1 - .../sessionstore/SessionComponents.manifest | 5 + .../sessionstore/ZenSessionManager.sys.mjs | 16 +- src/zen/sessionstore/ZenWindowSync.sys.mjs | 23 ++ src/zen/sessionstore/moz.build | 1 + src/zen/workspaces/ZenWindowSyncing.mjs | 308 ------------------ 7 files changed, 38 insertions(+), 317 deletions(-) create mode 100644 src/zen/sessionstore/ZenWindowSync.sys.mjs delete mode 100644 src/zen/workspaces/ZenWindowSyncing.mjs diff --git a/src/browser/base/content/zen-assets.inc.xhtml b/src/browser/base/content/zen-assets.inc.xhtml index a61105b51..4d9cf90b3 100644 --- a/src/browser/base/content/zen-assets.inc.xhtml +++ b/src/browser/base/content/zen-assets.inc.xhtml @@ -57,4 +57,3 @@ - diff --git a/src/browser/base/content/zen-assets.jar.inc.mn b/src/browser/base/content/zen-assets.jar.inc.mn index efee1ce48..d42187d8a 100644 --- a/src/browser/base/content/zen-assets.jar.inc.mn +++ b/src/browser/base/content/zen-assets.jar.inc.mn @@ -41,7 +41,6 @@ content/browser/zen-components/ZenWorkspaceIcons.mjs (../../zen/workspaces/ZenWorkspaceIcons.mjs) content/browser/zen-components/ZenWorkspace.mjs (../../zen/workspaces/ZenWorkspace.mjs) content/browser/zen-components/ZenWorkspaces.mjs (../../zen/workspaces/ZenWorkspaces.mjs) - content/browser/zen-components/ZenWindowSyncing.mjs (../../zen/workspaces/ZenWindowSyncing.mjs) content/browser/zen-components/ZenWorkspaceCreation.mjs (../../zen/workspaces/ZenWorkspaceCreation.mjs) content/browser/zen-components/ZenWorkspacesStorage.mjs (../../zen/workspaces/ZenWorkspacesStorage.mjs) content/browser/zen-components/ZenWorkspacesSync.mjs (../../zen/workspaces/ZenWorkspacesSync.mjs) diff --git a/src/zen/sessionstore/SessionComponents.manifest b/src/zen/sessionstore/SessionComponents.manifest index f8f08d1d7..9da9dc105 100644 --- a/src/zen/sessionstore/SessionComponents.manifest +++ b/src/zen/sessionstore/SessionComponents.manifest @@ -4,3 +4,8 @@ # Browser global components initializing before UI startup category browser-before-ui-startup resource:///modules/zen/ZenSessionManager.sys.mjs ZenSessionStore.init +category browser-before-ui-startup resource:///modules/zen/ZenWindowSync.sys.mjs ZenWindowSync.init + +# App shutdown consumers +category browser-quit-application-granted resource:///modules/zen/ZenSessionManager.sys.mjs ZenSessionStore.uninit +category browser-quit-application-granted resource:///modules/zen/ZenWindowSync.sys.mjs ZenWindowSync.uninit diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 2a229daca..06478075e 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -25,7 +25,15 @@ class nsZenSessionManager { // Called from SessionComponents.manifest on app-startup init() { - this.#initObservers(); + for (let topic of OBSERVING) { + Services.obs.addObserver(this, topic); + } + } + + uninit() { + for (let topic of OBSERVING) { + Services.obs.removeObserver(this, topic); + } } async readFile() { @@ -38,12 +46,6 @@ class nsZenSessionManager { } } - #initObservers() { - for (let topic of OBSERVING) { - Services.obs.addObserver(this, topic); - } - } - get #sidebar() { return this.#file.sidebar; } diff --git a/src/zen/sessionstore/ZenWindowSync.sys.mjs b/src/zen/sessionstore/ZenWindowSync.sys.mjs new file mode 100644 index 000000000..a96e09687 --- /dev/null +++ b/src/zen/sessionstore/ZenWindowSync.sys.mjs @@ -0,0 +1,23 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +const OBSERVING = ['browser-window-before-show']; + +class nsZenWindowSync { + constructor() {} + + init() { + for (let topic of OBSERVING) { + Services.obs.addObserver(this, topic); + } + } + + uninit() { + for (let topic of OBSERVING) { + Services.obs.removeObserver(this, topic); + } + } +} + +export const ZenWindowSync = new nsZenWindowSync(); diff --git a/src/zen/sessionstore/moz.build b/src/zen/sessionstore/moz.build index af5a7dd3b..902ae2a30 100644 --- a/src/zen/sessionstore/moz.build +++ b/src/zen/sessionstore/moz.build @@ -5,4 +5,5 @@ EXTRA_JS_MODULES.zen += [ "ZenSessionFile.sys.mjs", "ZenSessionManager.sys.mjs", + "ZenWindowSync.sys.mjs", ] diff --git a/src/zen/workspaces/ZenWindowSyncing.mjs b/src/zen/workspaces/ZenWindowSyncing.mjs deleted file mode 100644 index 4c06ae0e0..000000000 --- a/src/zen/workspaces/ZenWindowSyncing.mjs +++ /dev/null @@ -1,308 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -{ - class nsZenWorkspaceWindowSync extends nsZenMultiWindowFeature { - #ignoreNextEvents = false; - #waitForPromise = null; - - constructor() { - super(); - if (!window.closed) { - this.init(); - } - } - - async init() { - await gZenWorkspaces.promiseInitialized; - this.#makeSureAllTabsHaveIds(); - this.#setUpEventListeners(); - } - - #makeSureAllTabsHaveIds() { - const allTabs = gZenWorkspaces.allStoredTabs; - for (const tab of allTabs) { - if (!tab.hasAttribute('zen-sync-id') && !tab.hasAttribute('zen-empty-tab')) { - const tabId = gZenUIManager.generateUuidv4(); - tab.setAttribute('zen-sync-id', tabId); - } - } - } - - #setUpEventListeners() { - const kEvents = [ - 'TabClose', - 'TabOpen', - 'TabMove', - - 'TabPinned', - 'TabUnpinned', - - 'TabAddedToEssentials', - 'TabRemovedFromEssentials', - - 'TabHide', - 'TabShow', - - 'ZenTabIconChanged', - 'ZenTabLabelChanged', - - 'TabGroupCreate', - 'TabGroupRemoved', - 'TabGrouped', - 'TabUngrouped', - 'TabGroupMoved', - ]; - const eventListener = this.#handleEvent.bind(this); - for (const event of kEvents) { - window.addEventListener(event, eventListener); - } - - window.addEventListener('unload', () => { - for (const event of kEvents) { - window.removeEventListener(event, eventListener); - } - }); - } - - #handleEvent(event) { - this.#propagateToOtherWindows(event); - } - - async #propagateToOtherWindows(event) { - if (this.#ignoreNextEvents) { - return; - } - if (this.#waitForPromise) { - await this.#waitForPromise; - } - this.#waitForPromise = new Promise((resolve) => { - this.foreachWindowAsActive(async (browser) => { - if (browser.gZenWorkspaceWindowSync && !this.windowIsActive(browser)) { - await browser.gZenWorkspaceWindowSync.onExternalTabEvent(event); - } - }).then(() => { - resolve(); - }); - }); - } - - async onExternalTabEvent(event) { - this.#ignoreNextEvents = true; - switch (event.type) { - case 'TabClose': - this.#onTabClose(event); - break; - case 'TabOpen': - await this.#onTabOpen(event); - break; - case 'TabPinned': - this.#onTabPinned(event); - break; - case 'TabUnpinned': - this.#onTabUnpinned(event); - break; - case 'TabAddedToEssentials': - this.#onTabAddedToEssentials(event); - break; - case 'TabRemovedFromEssentials': - this.#onTabRemovedFromEssentials(event); - break; - case 'TabHide': - this.#onTabHide(event); - break; - case 'TabShow': - this.#onTabShow(event); - break; - case 'TabMove': - case 'TabGroupMoved': - this.#onTabMove(event); - break; - case 'ZenTabIconChanged': - this.#onTabIconChanged(event); - break; - case 'ZenTabLabelChanged': - this.#onTabLabelChanged(event); - break; - case 'TabGroupCreate': - this.#onTabGroupCreate(event); - break; - case 'TabGroupRemoved': - case 'TabGrouped': - case 'TabUngrouped': - // Tab grouping changes are automatically synced by Firefox - break; - default: - console.warn(`Unhandled event type: ${event.type}`); - break; - } - this.#ignoreNextEvents = false; - } - - #getTabId(tab) { - return tab.getAttribute('zen-sync-id'); - } - - #getTabWithId(tabId) { - for (const tab of gZenWorkspaces.allStoredTabs) { - if (this.#getTabId(tab) === tabId) { - return tab; - } - } - return null; - } - - #onTabClose(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToClose = this.#getTabWithId(tabId); - if (tabToClose) { - gBrowser.removeTab(tabToClose); - } - } - - #onTabPinned(event) { - const targetTab = event.target; - if (targetTab.hasAttribute('zen-essential')) { - return this.#onTabAddedToEssentials(event); - } - const tabId = this.#getTabId(targetTab); - const elementIndex = targetTab.elementIndex; - const tabToPin = this.#getTabWithId(tabId); - if (tabToPin) { - gBrowser.pinTab(tabToPin); - gBrowser.moveTabTo(tabToPin, { elementIndex, forceUngrouped: !!targetTab.group }); - } - } - - #onTabUnpinned(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToUnpin = this.#getTabWithId(tabId); - if (tabToUnpin) { - gBrowser.unpinTab(tabToUnpin); - } - } - - #onTabIconChanged(event) { - this.#updateTabIconAndLabel(event); - } - - #onTabLabelChanged(event) { - this.#updateTabIconAndLabel(event); - } - - #updateTabIconAndLabel(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToChange = this.#getTabWithId(tabId); - if (tabToChange && tabToChange.hasAttribute('pending')) { - gBrowser.setIcon(tabToChange, gBrowser.getIcon(targetTab)); - gBrowser._setTabLabel(tabToChange, targetTab.label); - } - } - - #onTabAddedToEssentials(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToAdd = this.#getTabWithId(tabId); - if (tabToAdd) { - gZenPinnedTabManager.addToEssentials(tabToAdd); - } - } - - #onTabRemovedFromEssentials(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToRemove = this.#getTabWithId(tabId); - if (tabToRemove) { - gZenPinnedTabManager.removeFromEssentials(tabToRemove); - } - } - - #onTabHide(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToHide = this.#getTabWithId(tabId); - if (tabToHide) { - gBrowser.hideTab(tabToHide); - } - } - - #onTabShow(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToShow = this.#getTabWithId(tabId); - if (tabToShow) { - gBrowser.showTab(tabToShow); - } - } - - #onTabMove(event) { - const targetTab = event.target; - const tabId = this.#getTabId(targetTab); - const tabToMove = this.#getTabWithId(tabId); - const workspaceId = targetTab.getAttribute('zen-workspace-id'); - const isEssential = targetTab.hasAttribute('zen-essential'); - if (tabToMove) { - let tabSibling = targetTab.previousElementSibling; - let isFirst = false; - if (!tabSibling?.hasAttribute('zen-sync-id')) { - isFirst = true; - } - gBrowser.zenHandleTabMove(tabToMove, () => { - if (isFirst) { - let container; - if (isEssential) { - container = gZenWorkspaces.getEssentialsSection(tabToMove); - } else { - const workspaceElement = gZenWorkspaces.workspaceElement(workspaceId); - container = tabToMove.pinned - ? workspaceElement.pinnedTabsContainer - : workspaceElement.tabsContainer; - } - container.insertBefore(tabToMove, container.firstChild); - } else { - let relativeTab = gZenWorkspaces.allStoredTabs.find((tab) => { - return this.#getTabId(tab) === this.#getTabId(tabSibling); - }); - if (relativeTab) { - relativeTab.after(tabToMove); - } - } - }); - } - } - - async #onTabOpen(event) { - const targetTab = event.target; - const isPinned = targetTab.pinned; - const isEssential = isPinned && targetTab.hasAttribute('zen-essential'); - if (!this.#getTabId(targetTab) && !targetTab.hasAttribute('zen-empty-tab')) { - const tabId = gZenUIManager.generateUuidv4(); - targetTab.setAttribute('zen-sync-id', tabId); - } - const duplicatedTab = gBrowser.addTrustedTab(targetTab.linkedBrowser.currentURI.spec, { - createLazyBrowser: true, - essential: isEssential, - pinned: isPinned, - }); - if (!isEssential) { - gZenWorkspaces.moveTabToWorkspace( - duplicatedTab, - targetTab.getAttribute('zen-workspace-id') - ); - } - duplicatedTab.setAttribute('zen-sync-id', targetTab.getAttribute('zen-sync-id')); - } - - #onTabGroupCreate(event) { - void event; - //const targetGroup = event.target; - //const isSplitView = targetGroup.classList.contains('zen-split-view'); - //const isFolder = targetGroup.isZenFolder; - } - } - - window.gZenWorkspaceWindowSync = new nsZenWorkspaceWindowSync(); -} From ce986beb2f851e26e6d7b2e19f557dd79406cb43 Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Mon, 17 Nov 2025 18:51:14 +0100 Subject: [PATCH 18/18] feat: Run session saver before opening a new window, b=no-bug, c=no-component --- .../base/content/zen-assets.jar.inc.mn | 3 +- .../sessionstore/SessionStore-sys-mjs.patch | 33 +++++++++---------- .../sessionstore/ZenSessionManager.sys.mjs | 15 +++++---- .../ZenSessionStore.mjs | 0 src/zen/sessionstore/ZenWindowSync.sys.mjs | 2 ++ 5 files changed, 29 insertions(+), 24 deletions(-) rename src/zen/{common => sessionstore}/ZenSessionStore.mjs (100%) diff --git a/src/browser/base/content/zen-assets.jar.inc.mn b/src/browser/base/content/zen-assets.jar.inc.mn index d42187d8a..9c1208ecd 100644 --- a/src/browser/base/content/zen-assets.jar.inc.mn +++ b/src/browser/base/content/zen-assets.jar.inc.mn @@ -8,11 +8,12 @@ content/browser/zen-sets.js (../../zen/common/zen-sets.js) content/browser/ZenUIManager.mjs (../../zen/common/ZenUIManager.mjs) content/browser/zen-components/ZenCommonUtils.mjs (../../zen/common/ZenCommonUtils.mjs) - content/browser/zen-components/ZenSessionStore.mjs (../../zen/common/ZenSessionStore.mjs) content/browser/zen-components/ZenEmojisData.min.mjs (../../zen/common/emojis/ZenEmojisData.min.mjs) content/browser/zen-components/ZenEmojiPicker.mjs (../../zen/common/emojis/ZenEmojiPicker.mjs) content/browser/zen-components/ZenHasPolyfill.mjs (../../zen/common/ZenHasPolyfill.mjs) + content/browser/zen-components/ZenSessionStore.mjs (../../zen/sessionstore/ZenSessionStore.mjs) + * content/browser/zen-styles/zen-theme.css (../../zen/common/styles/zen-theme.css) content/browser/zen-styles/zen-buttons.css (../../zen/common/styles/zen-buttons.css) content/browser/zen-styles/zen-browser-ui.css (../../zen/common/styles/zen-browser-ui.css) diff --git a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch index c778b4fd5..324d80b99 100644 --- a/src/browser/components/sessionstore/SessionStore-sys-mjs.patch +++ b/src/browser/components/sessionstore/SessionStore-sys-mjs.patch @@ -1,5 +1,5 @@ diff --git a/browser/components/sessionstore/SessionStore.sys.mjs b/browser/components/sessionstore/SessionStore.sys.mjs -index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc3315aa98 100644 +index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..ad80ed937f696ba2800e62dfc11fcfb90e3f1092 100644 --- a/browser/components/sessionstore/SessionStore.sys.mjs +++ b/browser/components/sessionstore/SessionStore.sys.mjs @@ -127,6 +127,8 @@ const TAB_EVENTS = [ @@ -36,18 +36,17 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc !lazy.SessionStartup.willRestore() ) { // We want to split the window up into pinned tabs and unpinned tabs. -@@ -2215,6 +2219,10 @@ var SessionStoreInternal = { +@@ -2215,6 +2219,9 @@ var SessionStoreInternal = { }); this._shouldRestoreLastSession = false; } + else if (!aInitialState && isRegularWindow) { -+ aInitialState = lazy.ZenSessionStore.getNewWindowData(); -+ this.restoreWindows(aWindow, aInitialState, {}); ++ lazy.ZenSessionStore.restoreNewWindow(aWindow, this); + } if (this._restoreLastWindow && aWindow.toolbar.visible) { // always reset (if not a popup window) -@@ -2384,11 +2392,9 @@ var SessionStoreInternal = { +@@ -2384,11 +2391,9 @@ var SessionStoreInternal = { tabbrowser.selectedTab.label; } @@ -59,7 +58,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc // Store the window's close date to figure out when each individual tab // was closed. This timestamp should allow re-arranging data based on how -@@ -3373,7 +3379,7 @@ var SessionStoreInternal = { +@@ -3373,7 +3378,7 @@ var SessionStoreInternal = { if (!isPrivateWindow && tabState.isPrivate) { return; } @@ -68,7 +67,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc return; } -@@ -4089,6 +4095,11 @@ var SessionStoreInternal = { +@@ -4089,6 +4094,11 @@ var SessionStoreInternal = { Math.min(tabState.index, tabState.entries.length) ); tabState.pinned = false; @@ -80,7 +79,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc if (inBackground === false) { aWindow.gBrowser.selectedTab = newTab; -@@ -4525,6 +4536,7 @@ var SessionStoreInternal = { +@@ -4525,6 +4535,7 @@ var SessionStoreInternal = { // Append the tab if we're opening into a different window, tabIndex: aSource == aTargetWindow ? pos : Infinity, pinned: state.pinned, @@ -88,7 +87,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc userContextId: state.userContextId, skipLoad: true, preferredRemoteType, -@@ -5374,7 +5386,7 @@ var SessionStoreInternal = { +@@ -5374,7 +5385,7 @@ var SessionStoreInternal = { for (let i = tabbrowser.pinnedTabCount; i < tabbrowser.tabs.length; i++) { let tab = tabbrowser.tabs[i]; @@ -97,7 +96,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc removableTabs.push(tab); } } -@@ -5434,7 +5446,7 @@ var SessionStoreInternal = { +@@ -5434,7 +5445,7 @@ var SessionStoreInternal = { } let workspaceID = aWindow.getWorkspaceID(); @@ -106,7 +105,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc winData.workspaceID = workspaceID; } }, -@@ -5625,11 +5637,12 @@ var SessionStoreInternal = { +@@ -5625,11 +5636,12 @@ var SessionStoreInternal = { } let tabbrowser = aWindow.gBrowser; @@ -120,7 +119,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc // update the internal state data for this window for (let tab of tabs) { if (tab == aWindow.FirefoxViewHandler.tab) { -@@ -5640,6 +5653,7 @@ var SessionStoreInternal = { +@@ -5640,6 +5652,7 @@ var SessionStoreInternal = { tabsData.push(tabData); } @@ -128,7 +127,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc // update tab group state for this window winData.groups = []; for (let tabGroup of aWindow.gBrowser.tabGroups) { -@@ -5652,7 +5666,7 @@ var SessionStoreInternal = { +@@ -5652,7 +5665,7 @@ var SessionStoreInternal = { // a window is closed, point to the first item in the tab strip instead (it will never be the Firefox View tab, // since it's only inserted into the tab strip after it's selected). if (aWindow.FirefoxViewHandler.tab?.selected) { @@ -137,7 +136,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc winData.title = tabbrowser.tabs[0].label; } winData.selected = selectedIndex; -@@ -5764,8 +5778,8 @@ var SessionStoreInternal = { +@@ -5764,8 +5777,8 @@ var SessionStoreInternal = { // selectTab represents. let selectTab = 0; if (overwriteTabs) { @@ -148,7 +147,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc selectTab = Math.min(selectTab, winData.tabs.length); } -@@ -5808,6 +5822,8 @@ var SessionStoreInternal = { +@@ -5808,6 +5821,8 @@ var SessionStoreInternal = { winData.tabs, winData.groups ?? [] ); @@ -157,7 +156,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc this._log.debug( `restoreWindow, createTabsForSessionRestore returned ${tabs.length} tabs` ); -@@ -6371,6 +6387,25 @@ var SessionStoreInternal = { +@@ -6371,6 +6386,25 @@ var SessionStoreInternal = { // Most of tabData has been restored, now continue with restoring // attributes that may trigger external events. @@ -183,7 +182,7 @@ index 1cdbc0f41bf5b55dfbbd850cb618c6d870f7a261..7cd5b92c1b1ddbaea89de5e9627fc5bc if (tabData.pinned) { tabbrowser.pinTab(tab); -@@ -7289,7 +7324,7 @@ var SessionStoreInternal = { +@@ -7289,7 +7323,7 @@ var SessionStoreInternal = { let groupsToSave = new Map(); for (let tIndex = 0; tIndex < window.tabs.length; ) { diff --git a/src/zen/sessionstore/ZenSessionManager.sys.mjs b/src/zen/sessionstore/ZenSessionManager.sys.mjs index 06478075e..914a3eb6d 100644 --- a/src/zen/sessionstore/ZenSessionManager.sys.mjs +++ b/src/zen/sessionstore/ZenSessionManager.sys.mjs @@ -157,12 +157,15 @@ class nsZenSessionManager { aWindowData.groups = sidebar.groups; } - getNewWindowData() { - lazy.SessionSaver.run(); - const state = lazy.SessionStore.getCurrentState(true); - const windows = state.windows || {}; - let newWindow = Cu.cloneInto(windows[0], {}); - return { windows: [newWindow] }; + restoreNewWindow(aWindow, SessionStoreInternal) { + lazy.SessionSaver.run().then(() => { + const state = lazy.SessionStore.getCurrentState(true); + const windows = state.windows || {}; + let newWindow = Cu.cloneInto(windows[0], {}); + delete newWindow.selected; + const newState = { windows: [newWindow] }; + SessionStoreInternal.restoreWindows(aWindow, newState, {}); + }); } } diff --git a/src/zen/common/ZenSessionStore.mjs b/src/zen/sessionstore/ZenSessionStore.mjs similarity index 100% rename from src/zen/common/ZenSessionStore.mjs rename to src/zen/sessionstore/ZenSessionStore.mjs diff --git a/src/zen/sessionstore/ZenWindowSync.sys.mjs b/src/zen/sessionstore/ZenWindowSync.sys.mjs index a96e09687..21bc6c230 100644 --- a/src/zen/sessionstore/ZenWindowSync.sys.mjs +++ b/src/zen/sessionstore/ZenWindowSync.sys.mjs @@ -18,6 +18,8 @@ class nsZenWindowSync { Services.obs.removeObserver(this, topic); } } + + observe(aSubject, aTopic) {} } export const ZenWindowSync = new nsZenWindowSync();