feat: Make sure sessions are correctly migrated on first run, b=no-bug, c=workspaces

This commit is contained in:
mr. m
2026-01-19 17:18:14 +01:00
parent f1871cfb6d
commit a3494d12e6
7 changed files with 55 additions and 19 deletions

View File

@@ -10,3 +10,6 @@
- name: zen.session-store.restore-unsynced-windows
value: true
- name: zen.session-store.reduce-sessionstore-write-size
value: true

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/sessionstore/SessionSaver.sys.mjs b/browser/components/sessionstore/SessionSaver.sys.mjs
index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..6906fd9be7ae6ca4316133e0d6552b797c54a7ec 100644
index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..a4ce5de45f13eaa22803083eccb4e48a054fee39 100644
--- a/browser/components/sessionstore/SessionSaver.sys.mjs
+++ b/browser/components/sessionstore/SessionSaver.sys.mjs
@@ -20,6 +20,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
@@ -27,3 +27,24 @@ index 9141793550f7c7ff6aa63d4c85bf571b4499e2d0..6906fd9be7ae6ca4316133e0d6552b79
return this._writeState(state);
},
@@ -372,7 +374,19 @@ var SessionSaverInternal = {
// Write (atomically) to a session file, using a tmp file. Once the session
// file is successfully updated, save the time stamp of the last save and
// notify the observers.
- return lazy.SessionFile.write(state).then(
+ let stateToWrite = Cu.cloneInto(state, {});
+ if (Services.prefs.getBoolPref("zen.session-store.reduce-sessionstore-write-size", true)) {
+ for (let i = 0; i < stateToWrite.windows.length; i++) {
+ let win = stateToWrite.windows[i];
+ if (win.isPopup || win.isTaskbarTab || win.isZenUnsynced) {
+ continue;
+ }
+ win.tabs = [];
+ win.folders = [];
+ win.groups = [];
+ }
+ }
+ return lazy.SessionFile.write(stateToWrite).then(
() => {
this.updateLastSaveTime();
if (!lazy.RunState.isRunning) {

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/sessionstore/SessionStartup.sys.mjs b/browser/components/sessionstore/SessionStartup.sys.mjs
index 86600ffb5178599ab23270a964064ca657a3283f..ffb22990e7d9e1b79f276fe5c1eb38f2b869a57b 100644
index 86600ffb5178599ab23270a964064ca657a3283f..e7014e5bce547d37ec92377a95bad5be4d52152e 100644
--- a/browser/components/sessionstore/SessionStartup.sys.mjs
+++ b/browser/components/sessionstore/SessionStartup.sys.mjs
@@ -40,6 +40,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
@@ -23,7 +23,7 @@ index 86600ffb5178599ab23270a964064ca657a3283f..ffb22990e7d9e1b79f276fe5c1eb38f2
this._initialState = parsed;
}
+ lazy.ZenSessionStore.onFileRead(this._initialState);
+ this._initialState = lazy.ZenSessionStore.onFileRead(this._initialState);
+
if (this._initialState == null) {
// No valid session found.

View File

@@ -1,5 +1,5 @@
diff --git a/browser/components/sessionstore/TabState.sys.mjs b/browser/components/sessionstore/TabState.sys.mjs
index 82721356d191055bec0d4b0ca49e481221988801..238d6ae1a4261e098d1e986e3c3df813d9d625f3 100644
index 82721356d191055bec0d4b0ca49e481221988801..68437e6f9fa54fc75ca9e24d738e8afcd0ea22f8 100644
--- a/browser/components/sessionstore/TabState.sys.mjs
+++ b/browser/components/sessionstore/TabState.sys.mjs
@@ -85,7 +85,24 @@ class _TabState {
@@ -8,7 +8,7 @@ index 82721356d191055bec0d4b0ca49e481221988801..238d6ae1a4261e098d1e986e3c3df813
+ tabData.zenWorkspace = tab.getAttribute("zen-workspace-id");
+ tabData.zenSyncId = tab.getAttribute("id");
+ tabData.zenEssential = tab.getAttribute("zen-essential");
+ tabData.zenEssential = tab.getAttribute("zen-essential") === "true";
+ tabData.pinned = tabData.pinned || tabData.zenEssential;
+ tabData.zenDefaultUserContextId = tab.getAttribute("zenDefaultUserContextId");
+ tabData.zenPinnedIcon = tab.getAttribute("zen-pinned-icon");

View File

@@ -198,7 +198,7 @@ export class nsZenSessionManager {
*/
onFileRead(initialState) {
if (!lazy.gWindowSyncEnabled) {
return;
return initialState;
}
// For the first time after migration, we restore the tabs
// That where going to be restored by SessionStore. The sidebar
@@ -235,19 +235,26 @@ export class nsZenSessionManager {
"zen.session-store.restore-unsynced-windows",
true
);
this.log(`Restoring Zen session data into ${initialState.windows?.length || 0} windows`);
for (let i = 0; i < initialState.windows.length; i++) {
let winData = initialState.windows[i];
if (winData.isZenUnsynced) {
if (!allowRestoreUnsynced) {
// We don't wan't to restore any unsynced windows with the sidebar data.
this.log("Skipping restore of unsynced window");
delete initialState.windows[i];
if (!this._shouldRunMigration) {
this.log(`Restoring Zen session data into ${initialState.windows?.length || 0} windows`);
for (let i = 0; i < initialState.windows.length; i++) {
let winData = initialState.windows[i];
if (winData.isZenUnsynced) {
if (!allowRestoreUnsynced) {
// We don't wan't to restore any unsynced windows with the sidebar data.
this.log("Skipping restore of unsynced window");
delete initialState.windows[i];
}
continue;
}
continue;
this.#restoreWindowData(winData);
}
this.#restoreWindowData(winData);
} else {
this.log("Saving windata state after migration");
this.saveState(initialState);
}
delete this._shouldRunMigration;
return initialState;
}
get #sidebar() {
@@ -304,9 +311,7 @@ export class nsZenSessionManager {
}
// Save the state to the sidebar object so that it gets written
// to the session file.
this.saveState(initialState);
delete this._migrationData;
delete this._shouldRunMigration;
}
/**

View File

@@ -56,6 +56,7 @@ const SYNC_FLAG_ICON = 1 << 1;
const SYNC_FLAG_MOVE = 1 << 2;
class nsZenWindowSync {
#initialized = false;
constructor() {}
/**
@@ -139,9 +140,10 @@ class nsZenWindowSync {
}
init() {
if (!lazy.gWindowSyncEnabled) {
if (!lazy.gWindowSyncEnabled || this.#initialized) {
return;
}
this.#initialized = true;
for (let topic of OBSERVING) {
Services.obs.addObserver(this, topic);
}
@@ -151,6 +153,10 @@ class nsZenWindowSync {
}
uninit() {
if (!this.#initialized) {
return;
}
this.#initialized = false;
for (let topic of OBSERVING) {
Services.obs.removeObserver(this, topic);
}

View File

@@ -1129,6 +1129,7 @@ class nsZenWorkspaces {
(tab.pinned && tab.hasAttribute("zen-empty-tab") && !tab.group)
) {
// Remove any tabs where their workspace doesn't exist anymore
this.log("Removed zombie tab from non-existing workspace", tab);
gBrowser.unpinTab(tab);
gBrowser.removeTab(tab, {
skipSessionStore: true,