Skip to content
Merged
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
33 changes: 24 additions & 9 deletions src/zen/spaces/ZenSpaceBookmarksStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ window.ZenWorkspaceBookmarksStorage = {
if (!window.gZenWorkspaces) {
return;
}
this.promiseInitialized = new Promise(resolve => {
this._resolveInitialized = resolve;
});
await this._ensureTable();
},

Expand Down Expand Up @@ -54,9 +57,12 @@ window.ZenWorkspaceBookmarksStorage = {

// Create index for changes tracking
await db.execute(`
CREATE INDEX IF NOT EXISTS idx_bookmarks_workspaces_changes
ON zen_bookmarks_workspaces_changes(bookmark_guid, workspace_uuid)
`);
CREATE INDEX IF NOT EXISTS idx_bookmarks_workspaces_changes
ON zen_bookmarks_workspaces_changes(bookmark_guid, workspace_uuid)
`);

this._resolveInitialized();
delete this._resolveInitialized;
}
);
},
Expand All @@ -68,6 +74,7 @@ window.ZenWorkspaceBookmarksStorage = {
*/
async updateLastChangeTimestamp(db) {
const now = Date.now();
await this.promiseInitialized;
await db.execute(
`
INSERT OR REPLACE INTO moz_meta (key, value)
Expand All @@ -84,23 +91,29 @@ window.ZenWorkspaceBookmarksStorage = {
*/
async getLastChangeTimestamp() {
const db = await this.lazy.PlacesUtils.promiseDBConnection();
await this.promiseInitialized;
const result = await db.executeCached(`
SELECT value FROM moz_meta WHERE key = 'zen_bookmarks_workspaces_last_change'
`);
return result.length ? parseInt(result[0].getResultByName("value"), 10) : 0;
},

async getBookmarkWorkspaces(bookmarkGuid) {
await this.promiseInitialized;
const db = await this.lazy.PlacesUtils.promiseDBConnection();

const rows = await db.execute(
`
let rows = [];
try {
rows = await db.execute(
`
SELECT workspace_uuid
FROM zen_bookmarks_workspaces
WHERE bookmark_guid = :bookmark_guid
`,
{ bookmark_guid: bookmarkGuid }
);
{ bookmark_guid: bookmarkGuid }
);
} catch (e) {
console.error("Error fetching bookmark workspaces:", e);
}

return rows.map(row => row.getResultByName("workspace_uuid"));
},
Expand All @@ -117,8 +130,8 @@ window.ZenWorkspaceBookmarksStorage = {
* }
*/
async getBookmarkGuidsByWorkspace() {
await this.promiseInitialized;
const db = await this.lazy.PlacesUtils.promiseDBConnection();

const rows = await db.execute(`
SELECT workspace_uuid, GROUP_CONCAT(bookmark_guid) as bookmark_guids
FROM zen_bookmarks_workspaces
Expand All @@ -141,6 +154,7 @@ window.ZenWorkspaceBookmarksStorage = {
* @returns {Promise<object>} An object mapping bookmark+workspace pairs to their change data.
*/
async getChangedIDs() {
await this.promiseInitialized;
const db = await this.lazy.PlacesUtils.promiseDBConnection();
const rows = await db.execute(`
SELECT bookmark_guid, workspace_uuid, change_type, timestamp
Expand All @@ -162,6 +176,7 @@ window.ZenWorkspaceBookmarksStorage = {
* Clear all recorded changes.
*/
async clearChangedIDs() {
await this.promiseInitialized;
await this.lazy.PlacesUtils.withConnectionWrapper(
"ZenWorkspaceBookmarksStorage.clearChangedIDs",
async db => {
Expand Down
25 changes: 24 additions & 1 deletion src/zen/spaces/ZenSpaceManager.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,12 +1261,23 @@ class nsZenWorkspaces {
}

removeWorkspace(windowID) {
let { promise, resolve } = Promise.withResolvers();
this.#deleteWorkspaceOwnedTabs(windowID);
let workspacesData = this.getWorkspaces();
// Remove the workspace from the cache
workspacesData = workspacesData.filter(
workspace => workspace.uuid !== windowID
);
window.addEventListener(
"ZenWorkspacesUIUpdate",
() => {
resolve();
},
{ once: true }
);
this.#propagateWorkspaceData(workspacesData);
gBrowser.tabContainer._invalidateCachedVisibleTabs();
return promise;
}

isWorkspaceActive(workspace) {
Expand Down Expand Up @@ -1472,6 +1483,18 @@ class nsZenWorkspaces {
});
}

#deleteWorkspaceOwnedTabs(workspaceID) {
const tabs = this.allStoredTabs.filter(
tab =>
tab.getAttribute("zen-workspace-id") === workspaceID &&
!tab.hasAttribute("zen-essential") &&
!(tab.hasAttribute("zen-empty-tab") && !tab.group)
);
gBrowser.removeTabs(tabs, {
closeWindowWithLastTab: false,
});
}

async unloadWorkspace() {
const workspaceId =
this.#contextMenuData?.workspaceId || this.activeWorkspace;
Expand Down Expand Up @@ -1659,7 +1682,7 @@ class nsZenWorkspaces {
onInit,
previousWorkspace.uuid
);
if (tabToSelect.linkedBrowser) {
if (tabToSelect?.linkedBrowser) {
gBrowser.warmupTab(tabToSelect);
}

Expand Down
2 changes: 1 addition & 1 deletion src/zen/tests/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ BROWSER_CHROME_MANIFESTS += [
"glance/browser.toml",
"live-folders/browser.toml",
"pinned/browser.toml",
"spaces/browser.toml",
"split_view/browser.toml",
"tabs/browser.toml",
"ub-actions/browser.toml",
"urlbar/browser.toml",
"welcome/browser.toml",
"window_sync/browser.toml",
"workspaces/browser.toml",
]

DIRS += [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ add_task(async function test_Check_Creation() {
await gZenWorkspaces.removeWorkspace(gZenWorkspaces.activeWorkspace);
const workspacesAfterRemove = gZenWorkspaces.getWorkspaces();
Assert.strictEqual(
workspacesAfterRemove.workspaces.length,
workspacesAfterRemove.length,
1,
"One workspace should exist."
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"use strict";

add_task(async function test_Issue_10455() {
debugger;
await SpecialPowers.pushPrefEnv({
set: [["browser.tabs.closeWindowWithLastTab", true]],
});
Expand All @@ -24,6 +25,7 @@ add_task(async function test_Issue_10455() {
});

add_task(async function test_Issue_10455_Dont_Close() {
debugger;
await SpecialPowers.pushPrefEnv({
set: [["browser.tabs.closeWindowWithLastTab", false]],
});
Expand Down
File renamed without changes.
132 changes: 0 additions & 132 deletions src/zen/tests/workspaces/browser_workspace_unload.js

This file was deleted.

Loading