mirror of
https://github.com/zen-browser/components.git
synced 2025-07-08 19:49:59 +02:00
feat(workspace): Move observer notifications to workspaces storage
This commit is contained in:
parent
863dcfa705
commit
86578cb4d3
3 changed files with 14 additions and 11 deletions
|
@ -209,7 +209,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
this._workspaceCache = null;
|
this._workspaceCache = null;
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
await this._updateWorkspacesChangeContextMenu();
|
await this._updateWorkspacesChangeContextMenu();
|
||||||
Services.obs.notifyObservers(null, "zen-workspace-removed", windowID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isWorkspaceActive(workspace) {
|
isWorkspaceActive(workspace) {
|
||||||
|
@ -559,7 +558,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
workspaceData.name = workspaceName;
|
workspaceData.name = workspaceName;
|
||||||
workspaceData.icon = icon?.label;
|
workspaceData.icon = icon?.label;
|
||||||
await this.saveWorkspace(workspaceData);
|
await this.saveWorkspace(workspaceData);
|
||||||
Services.obs.notifyObservers(null, "zen-workspace-updated", workspaceData.uuid);
|
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,7 +681,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
}
|
}
|
||||||
let workspaceData = this._createWorkspaceData(name, isDefault, icon);
|
let workspaceData = this._createWorkspaceData(name, isDefault, icon);
|
||||||
await this.saveWorkspace(workspaceData);
|
await this.saveWorkspace(workspaceData);
|
||||||
Services.obs.notifyObservers(null, "zen-workspace-added", workspaceData.uuid);
|
|
||||||
await this.changeWorkspace(workspaceData);
|
await this.changeWorkspace(workspaceData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -760,7 +757,6 @@ var ZenWorkspaces = new (class extends ZenMultiWindowFeature {
|
||||||
let userContextId = parseInt(event.target.getAttribute('data-usercontextid'));
|
let userContextId = parseInt(event.target.getAttribute('data-usercontextid'));
|
||||||
workspace.containerTabId = userContextId;
|
workspace.containerTabId = userContextId;
|
||||||
await this.saveWorkspace(workspace);
|
await this.saveWorkspace(workspace);
|
||||||
Services.obs.notifyObservers(null, "zen-workspace-updated", workspace.uuid);
|
|
||||||
await this._propagateWorkspaceData();
|
await this._propagateWorkspaceData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ var ZenWorkspacesStorage = {
|
||||||
container_id INTEGER,
|
container_id INTEGER,
|
||||||
position INTEGER NOT NULL DEFAULT 0,
|
position INTEGER NOT NULL DEFAULT 0,
|
||||||
created_at INTEGER NOT NULL,
|
created_at INTEGER NOT NULL,
|
||||||
updated_at INTEGER NOT NULL,
|
updated_at INTEGER NOT NULL
|
||||||
)
|
)
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ var ZenWorkspacesStorage = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveWorkspace(workspace) {
|
async saveWorkspace(workspace, notifyObservers = true) {
|
||||||
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.saveWorkspace', async (db) => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.saveWorkspace', async (db) => {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
|
@ -114,6 +114,10 @@ var ZenWorkspacesStorage = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(notifyObservers) {
|
||||||
|
Services.obs.notifyObservers(null, "zen-workspace-updated", workspace.uuid);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getWorkspaces() {
|
async getWorkspaces() {
|
||||||
|
@ -131,7 +135,7 @@ var ZenWorkspacesStorage = {
|
||||||
}));
|
}));
|
||||||
},
|
},
|
||||||
|
|
||||||
async removeWorkspace(uuid) {
|
async removeWorkspace(uuid, notifyObservers = true) {
|
||||||
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.removeWorkspace', async (db) => {
|
await PlacesUtils.withConnectionWrapper('ZenWorkspacesStorage.removeWorkspace', async (db) => {
|
||||||
await db.execute(
|
await db.execute(
|
||||||
`
|
`
|
||||||
|
@ -150,6 +154,10 @@ var ZenWorkspacesStorage = {
|
||||||
timestamp: Math.floor(now / 1000)
|
timestamp: Math.floor(now / 1000)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(notifyObservers) {
|
||||||
|
Services.obs.notifyObservers(null, "zen-workspace-removed", uuid);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async wipeAllWorkspaces() {
|
async wipeAllWorkspaces() {
|
||||||
|
|
|
@ -68,7 +68,7 @@ ZenWorkspacesStore.prototype.changeItemID = async function (oldID, newID) {
|
||||||
const workspace = workspaces.find(ws => ws.uuid === oldID);
|
const workspace = workspaces.find(ws => ws.uuid === oldID);
|
||||||
if (workspace) {
|
if (workspace) {
|
||||||
workspace.uuid = newID;
|
workspace.uuid = newID;
|
||||||
await ZenWorkspacesStorage.saveWorkspace(workspace);
|
await ZenWorkspacesStorage.saveWorkspace(workspace,false);
|
||||||
// Mark the new ID as changed for sync
|
// Mark the new ID as changed for sync
|
||||||
await ZenWorkspacesStorage.markChanged(newID);
|
await ZenWorkspacesStorage.markChanged(newID);
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ ZenWorkspacesStore.prototype.create = async function (record) {
|
||||||
containerTabId: record.containerTabId,
|
containerTabId: record.containerTabId,
|
||||||
position: record.position
|
position: record.position
|
||||||
};
|
};
|
||||||
await ZenWorkspacesStorage.saveWorkspace(workspace);
|
await ZenWorkspacesStorage.saveWorkspace(workspace,false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._log.error(`Error creating workspace with ID ${record.id}`, error);
|
this._log.error(`Error creating workspace with ID ${record.id}`, error);
|
||||||
throw error;
|
throw error;
|
||||||
|
@ -165,8 +165,7 @@ ZenWorkspacesStore.prototype.update = async function (record) {
|
||||||
*/
|
*/
|
||||||
ZenWorkspacesStore.prototype.remove = async function (record) {
|
ZenWorkspacesStore.prototype.remove = async function (record) {
|
||||||
try {
|
try {
|
||||||
await ZenWorkspacesStorage.removeWorkspace(record.id);
|
await ZenWorkspacesStorage.removeWorkspace(record.id, false);
|
||||||
// Changes are already marked within ZenWorkspacesStorage.removeWorkspace
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._log.error(`Error removing workspace with ID ${record.id}`, error);
|
this._log.error(`Error removing workspace with ID ${record.id}`, error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue