From 86006c889149bf4d44ea166637b859242f56194f Mon Sep 17 00:00:00 2001 From: "Mr. M" Date: Sun, 28 Sep 2025 23:45:13 +0200 Subject: [PATCH] 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; + } +}