Skip to content

Commit

Permalink
fix: Bars getting merged due to usage of synced storage (#231)
Browse files Browse the repository at this point in the history
* fix: Do not use local storage

* fix. Do not use synced storage for storing active bars
  • Loading branch information
danielptv authored Dec 20, 2023
1 parent 0d9b002 commit 1e3a7eb
Showing 1 changed file with 7 additions and 15 deletions.
22 changes: 7 additions & 15 deletions src/background/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ async function getActiveWorkspaceId() {
}

/**
* Get an entry from the browser storage.
* The synced storage will only be accessed
* if the key is not present in the local storage.
* Get an entry from the local browser storage.
*
* @param key - The entry key.
* @returns The entry.
Expand All @@ -144,27 +142,21 @@ async function get<T>(key: string): Promise<T | undefined> {
const localData: Record<string, T> = await chrome.storage.local.get(key);

if (Object.keys(localData).length === 0 || localData[key] === undefined) {
const syncedData: Record<string, T> = await chrome.storage.sync.get(key);
if (Object.keys(syncedData).length === 0 || syncedData[key] === undefined) {
return undefined;
}
return syncedData[key];
return undefined;
}
return localData[key];
}

/**
* Set an entry in the browser storage.
* The entry will be set in both local
* and synced storage.
* Set an entry in the local browser storage.
*
* @param key - The entry key.
* @param value - The entry value.
*/
async function set<T>(key: string, value: T) {
const data: Record<string, T> = {};
data[key] = value;
await chrome.storage.local.set(data);
await chrome.storage.sync.set(data);
const localData: Record<string, T> = {};
localData[key] = value;
await chrome.storage.local.set(localData);
}

async function createDefaultBar() {
Expand Down

0 comments on commit 1e3a7eb

Please sign in to comment.