Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/zen/ZenComponents.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ category app-startup nsBrowserGlue @mozilla.org/browser/browserglue;1 applicatio

#include common/Components.manifest
#include sessionstore/SessionComponents.manifest
#include sync/SyncComponents.manifest
#include live-folders/LiveFoldersComponents.manifest
1 change: 1 addition & 0 deletions src/zen/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ DIRS += [
"toolkit",
"sessionstore",
"share",
"sync",
]
81 changes: 81 additions & 0 deletions src/zen/sessionstore/ZenSessionManager.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ export class nsZenSessionManager {
return PathUtils.join(PathUtils.profileDir, "zen-sessions-backup");
}

get sidebarData() {
return this.#sidebar;
}

get tabs() {
return this.sidebarData ? this.sidebarData.tabs || [] : [];
}

get folders() {
return this.sidebarData ? this.sidebarData.folders || [] : [];
}

get spaces() {
return this.sidebarData ? this.sidebarData.spaces || [] : [];
}

async #getBackupRecoveryOrder() {
// Also add the most recent backup file to the recovery order
let backupFiles = [PathUtils.join(this.#backupFolderPath, "clean.jsonlz4")];
Expand Down Expand Up @@ -524,9 +540,74 @@ export class nsZenSessionManager {
}
lazy.ZenLiveFoldersManager.saveState(soon);
this.#debounceRegeneration();
Services.obs.notifyObservers(null, "ZenWorkspaceDataChanged");
this.log(`Saving Zen session data with ${sidebar.tabs?.length || 0} tabs`);
}

/**
* Helper function to save the session file. Returns false if there is no file to save.
* Returns the result of the save operation otherwise.
*/
saveSessionFile(soon = false) {
if (!this.#file) {
return false;
}

if (soon) {
return this.#file.saveSoon();
}

return this.#file._save();
}

/**
* Called when there is new synced data from other windows.
*/
updateSyncedData({ tabs, folders, spaces }, soon = false) {
let sidebar = this.#sidebar;
if (tabs) {
sidebar.tabs = this.#filterUnusedTabs(tabs);
}
if (folders) {
sidebar.folders = folders;
}
if (spaces) {
sidebar.spaces = spaces;
}
this.#sidebar = sidebar;
return this.saveSessionFile(soon);
}

/**
* Called when tabs need to be synced to other windows.
*/
updateSyncedTabs(tabs, soon = false) {
let sidebar = this.#sidebar;
sidebar.tabs = this.#filterUnusedTabs(tabs);
this.#sidebar = sidebar;
return this.saveSessionFile(soon);
}

/**
* Called when folders need to be synced to other windows.
*/
updateSyncedFolders(folders, soon = false) {
let sidebar = this.#sidebar;
sidebar.folders = folders;
this.#sidebar = sidebar;
return this.saveSessionFile(soon);
}

/**
* Called when spaces need to be synced to other windows.
*/
updateSyncedSpaces(spaces, soon = false) {
let sidebar = this.#sidebar;
sidebar.spaces = spaces;
this.#sidebar = sidebar;
return this.saveSessionFile(soon);
}

/**
* Called when the last known backup should be deleted and a new one
* created. This uses the #deferredBackupTask to debounce clusters of
Expand Down
6 changes: 6 additions & 0 deletions src/zen/sync/SyncComponents.manifest
Original file line number Diff line number Diff line change
@@ -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/ZenWorkspacesSync.sys.mjs ZenWorkspacesSync.init
Loading