From 24d7af3da0ed598162fd075a65f87fb075b98016 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristijan=20Ribari=C4=87?= Date: Wed, 9 Oct 2024 18:14:09 +0200 Subject: [PATCH] Fix: Ensure tab context works after moving a tab to different workspace. Calling to _workspaces() always gets the fresh data from db, moved caching responsibility to db for getWorkspaces(). --- src/ZenWorkspaces.mjs | 27 +++++++++++++-------------- src/ZenWorkspacesStorage.mjs | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/ZenWorkspaces.mjs b/src/ZenWorkspaces.mjs index 6dbf538..af00a3c 100644 --- a/src/ZenWorkspaces.mjs +++ b/src/ZenWorkspaces.mjs @@ -72,24 +72,23 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature { } async _workspaces() { - if (!this._workspaceCache) { - this._workspaceCache = { workspaces: await ZenWorkspacesStorage.getWorkspaces() }; - // Get the active workspace ID from preferences - const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', ''); + this._workspaceCache = { workspaces: await ZenWorkspacesStorage.getWorkspaces() }; + // Get the active workspace ID from preferences + const activeWorkspaceId = Services.prefs.getStringPref('zen.workspaces.active', ''); - if (activeWorkspaceId) { - const activeWorkspace = this._workspaceCache.workspaces.find((w) => w.uuid === activeWorkspaceId); - // Set the active workspace ID to the first one if the one with selected id doesn't exist - if (!activeWorkspace) { - Services.prefs.setStringPref('zen.workspaces.active', this._workspaceCache.workspaces[0]?.uuid); - } - } else { - // Set the active workspace ID to the first one if active workspace doesn't exist + if (activeWorkspaceId) { + const activeWorkspace = this._workspaceCache.workspaces.find((w) => w.uuid === activeWorkspaceId); + // Set the active workspace ID to the first one if the one with selected id doesn't exist + if (!activeWorkspace) { Services.prefs.setStringPref('zen.workspaces.active', this._workspaceCache.workspaces[0]?.uuid); } - // sort by position - this._workspaceCache.workspaces.sort((a, b) => (a.position ?? Infinity) - (b.position ?? Infinity)); + } else { + // Set the active workspace ID to the first one if active workspace doesn't exist + Services.prefs.setStringPref('zen.workspaces.active', this._workspaceCache.workspaces[0]?.uuid); } + // sort by position + this._workspaceCache.workspaces.sort((a, b) => (a.position ?? Infinity) - (b.position ?? Infinity)); + return this._workspaceCache; } diff --git a/src/ZenWorkspacesStorage.mjs b/src/ZenWorkspacesStorage.mjs index 2dcbd93..2926b47 100644 --- a/src/ZenWorkspacesStorage.mjs +++ b/src/ZenWorkspacesStorage.mjs @@ -150,7 +150,7 @@ var ZenWorkspacesStorage = { async getWorkspaces() { const db = await PlacesUtils.promiseDBConnection(); - const rows = await db.execute(` + const rows = await db.executeCached(` SELECT * FROM zen_workspaces ORDER BY created_at ASC `); return rows.map((row) => ({