mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 16:40:00 +02:00
feat(workspaces): Use preferences to manage active workspace
This commit updates the workspaces system to use preferences to manage the active workspace, instead of storing the active state in each workspace object. The following changes were made: - **ZenWorkspaces.mjs:** - Removed the `used` property from workspace objects and replaced it with a preference (`zen.workspaces.active`) to store the active workspace ID. - Modified the `getActiveWorkspace` and `changeWorkspace` methods to use preferences instead of the `used` property. - Added a new `isWorkspaceActive` method to check if a workspace is active. - **ZenWorkspacesStorage.mjs:** - Removed the `is_active` column from the `zen_workspaces` table. - Removed the `setActiveWorkspace` method as the active workspace is now managed by preferences. This change simplifies the code and makes it easier to manage the active workspace across multiple browser windows and doesn't write to the database on every workspace change. Additionaly, it enables local active workspace selection when workspace sync is implemented.
This commit is contained in:
parent
511281c688
commit
9bcb66c768
2 changed files with 43 additions and 53 deletions
|
@ -13,7 +13,6 @@ var ZenWorkspacesStorage = {
|
|||
name TEXT NOT NULL,
|
||||
icon TEXT,
|
||||
is_default INTEGER NOT NULL DEFAULT 0,
|
||||
is_active INTEGER NOT NULL DEFAULT 0,
|
||||
container_id INTEGER,
|
||||
created_at INTEGER NOT NULL,
|
||||
updated_at INTEGER NOT NULL
|
||||
|
@ -27,9 +26,9 @@ var ZenWorkspacesStorage = {
|
|||
const now = Date.now();
|
||||
await db.executeCached(`
|
||||
INSERT OR REPLACE INTO zen_workspaces (
|
||||
uuid, name, icon, is_default, is_active, container_id, created_at, updated_at
|
||||
uuid, name, icon, is_default, container_id, created_at, updated_at
|
||||
) VALUES (
|
||||
:uuid, :name, :icon, :is_default, :is_active, :container_id,
|
||||
:uuid, :name, :icon, :is_default, :container_id,
|
||||
COALESCE((SELECT created_at FROM zen_workspaces WHERE uuid = :uuid), :now),
|
||||
:now
|
||||
)
|
||||
|
@ -38,7 +37,6 @@ var ZenWorkspacesStorage = {
|
|||
name: workspace.name,
|
||||
icon: workspace.icon || null,
|
||||
is_default: workspace.default ? 1 : 0,
|
||||
is_active: workspace.used ? 1 : 0,
|
||||
container_id: workspace.containerTabId || null,
|
||||
now
|
||||
});
|
||||
|
@ -50,13 +48,11 @@ var ZenWorkspacesStorage = {
|
|||
const rows = await db.execute(`
|
||||
SELECT * FROM zen_workspaces ORDER BY created_at ASC
|
||||
`);
|
||||
|
||||
return rows.map(row => ({
|
||||
uuid: row.getResultByName("uuid"),
|
||||
name: row.getResultByName("name"),
|
||||
icon: row.getResultByName("icon"),
|
||||
default: !!row.getResultByName("is_default"),
|
||||
used: !!row.getResultByName("is_active"),
|
||||
containerTabId: row.getResultByName("container_id")
|
||||
}));
|
||||
},
|
||||
|
@ -69,15 +65,6 @@ var ZenWorkspacesStorage = {
|
|||
});
|
||||
},
|
||||
|
||||
async setActiveWorkspace(uuid) {
|
||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage.setActiveWorkspace", async db => {
|
||||
await db.executeTransaction(async function() {
|
||||
await db.execute(`UPDATE zen_workspaces SET is_active = 0`);
|
||||
await db.execute(`UPDATE zen_workspaces SET is_active = 1 WHERE uuid = :uuid`, { uuid });
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
async setDefaultWorkspace(uuid) {
|
||||
await PlacesUtils.withConnectionWrapper("ZenWorkspacesStorage.setDefaultWorkspace", async db => {
|
||||
await db.executeTransaction(async function() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue