mirror of
https://github.com/zen-browser/components.git
synced 2025-07-07 21:19:57 +02:00
feat(zen-workspaces): Add workspace theme sync support
This commit adds support for syncing workspace themes across devices. The following changes were made: - Added theme properties to the Zen workspace schema: - `theme_type` (string): Type of theme (e.g., "gradient", "solid"). - `theme_colors` (JSON string): Array of gradient colors. - `theme_opacity` (number): Opacity of the theme. - `theme_rotation` (number): Rotation of the theme. - `theme_texture` (number): Texture of the theme. - Updated the `ZenWorkspacesSync` class to handle theme data. - Added validation for theme properties. - Updated the `ZenWorkspacesStorage` class to save and load workspace themes. - Bumped the `ZenWorkspacesEngine` version to 2.
This commit is contained in:
parent
182f221373
commit
06d85541b1
2 changed files with 52 additions and 4 deletions
|
@ -273,7 +273,8 @@ var ZenWorkspacesStorage = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async saveWorkspaceTheme(uuid, theme) {
|
async saveWorkspaceTheme(uuid, theme, notifyObservers = true) {
|
||||||
|
const changedUUIDs = [uuid];
|
||||||
await PlacesUtils.withConnectionWrapper('saveWorkspaceTheme', async (db) => {
|
await PlacesUtils.withConnectionWrapper('saveWorkspaceTheme', async (db) => {
|
||||||
await db.execute(`
|
await db.execute(`
|
||||||
UPDATE zen_workspaces
|
UPDATE zen_workspaces
|
||||||
|
@ -298,6 +299,10 @@ var ZenWorkspacesStorage = {
|
||||||
await this.markChanged(uuid);
|
await this.markChanged(uuid);
|
||||||
await this.updateLastChangeTimestamp(db);
|
await this.updateLastChangeTimestamp(db);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (notifyObservers) {
|
||||||
|
this._notifyWorkspacesChanged("zen-workspace-updated", changedUUIDs);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async getChangedIDs() {
|
async getChangedIDs() {
|
||||||
|
|
|
@ -20,7 +20,12 @@ Utils.deferGetSet(ZenWorkspaceRecord, "cleartext", [
|
||||||
"icon",
|
"icon",
|
||||||
"default",
|
"default",
|
||||||
"containerTabId",
|
"containerTabId",
|
||||||
"position"
|
"position",
|
||||||
|
"theme_type",
|
||||||
|
"theme_colors",
|
||||||
|
"theme_opacity",
|
||||||
|
"theme_rotation",
|
||||||
|
"theme_texture"
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Define ZenWorkspacesStore
|
// Define ZenWorkspacesStore
|
||||||
|
@ -111,6 +116,13 @@ ZenWorkspacesStore.prototype.createRecord = async function (id, collection) {
|
||||||
record.default = workspace.default;
|
record.default = workspace.default;
|
||||||
record.containerTabId = workspace.containerTabId;
|
record.containerTabId = workspace.containerTabId;
|
||||||
record.position = workspace.position;
|
record.position = workspace.position;
|
||||||
|
if (workspace.theme) {
|
||||||
|
record.theme_type = workspace.theme.type;
|
||||||
|
record.theme_colors = JSON.stringify(workspace.theme.gradientColors);
|
||||||
|
record.theme_opacity = workspace.theme.opacity;
|
||||||
|
record.theme_rotation = workspace.theme.rotation;
|
||||||
|
record.theme_texture = workspace.theme.texture;
|
||||||
|
}
|
||||||
record.deleted = false;
|
record.deleted = false;
|
||||||
} else {
|
} else {
|
||||||
record.deleted = true;
|
record.deleted = true;
|
||||||
|
@ -136,7 +148,14 @@ ZenWorkspacesStore.prototype.create = async function (record) {
|
||||||
icon: record.icon,
|
icon: record.icon,
|
||||||
default: record.default,
|
default: record.default,
|
||||||
containerTabId: record.containerTabId,
|
containerTabId: record.containerTabId,
|
||||||
position: record.position
|
position: record.position,
|
||||||
|
theme: record.theme_type ? {
|
||||||
|
type: record.theme_type,
|
||||||
|
gradientColors: JSON.parse(record.theme_colors),
|
||||||
|
opacity: record.theme_opacity,
|
||||||
|
rotation: record.theme_rotation,
|
||||||
|
texture: record.theme_texture
|
||||||
|
} : null
|
||||||
};
|
};
|
||||||
await ZenWorkspacesStorage.saveWorkspace(workspace,false);
|
await ZenWorkspacesStorage.saveWorkspace(workspace,false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -207,6 +226,30 @@ ZenWorkspacesStore.prototype._validateRecord = function (record) {
|
||||||
if(record.position != null && typeof record.position !== "number") {
|
if(record.position != null && typeof record.position !== "number") {
|
||||||
throw new Error(`Invalid position for workspace ID ${record.id}`);
|
throw new Error(`Invalid position for workspace ID ${record.id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate theme properties if they exist
|
||||||
|
if (record.theme_type) {
|
||||||
|
if (typeof record.theme_type !== "string") {
|
||||||
|
throw new Error(`Invalid theme_type for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
if (!record.theme_colors || typeof record.theme_colors !== "string") {
|
||||||
|
throw new Error(`Invalid theme_colors for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSON.parse(record.theme_colors);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Invalid theme_colors JSON for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
if (record.theme_opacity != null && typeof record.theme_opacity !== "number") {
|
||||||
|
throw new Error(`Invalid theme_opacity for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
if (record.theme_rotation != null && typeof record.theme_rotation !== "number") {
|
||||||
|
throw new Error(`Invalid theme_rotation for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
if (record.theme_texture != null && typeof record.theme_texture !== "number") {
|
||||||
|
throw new Error(`Invalid theme_texture for workspace ID ${record.id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -399,7 +442,7 @@ ZenWorkspacesEngine.prototype.constructor = ZenWorkspacesEngine;
|
||||||
ZenWorkspacesEngine.prototype._storeObj = ZenWorkspacesStore;
|
ZenWorkspacesEngine.prototype._storeObj = ZenWorkspacesStore;
|
||||||
ZenWorkspacesEngine.prototype._trackerObj = ZenWorkspacesTracker;
|
ZenWorkspacesEngine.prototype._trackerObj = ZenWorkspacesTracker;
|
||||||
ZenWorkspacesEngine.prototype._recordObj = ZenWorkspaceRecord;
|
ZenWorkspacesEngine.prototype._recordObj = ZenWorkspaceRecord;
|
||||||
ZenWorkspacesEngine.prototype.version = 1;
|
ZenWorkspacesEngine.prototype.version = 2;
|
||||||
|
|
||||||
ZenWorkspacesEngine.prototype.syncPriority = 10;
|
ZenWorkspacesEngine.prototype.syncPriority = 10;
|
||||||
ZenWorkspacesEngine.prototype.allowSkippedRecord = false;
|
ZenWorkspacesEngine.prototype.allowSkippedRecord = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue