Skip to content

Commit

Permalink
fix the storage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
SanCoder-Q committed Mar 26, 2024
1 parent 2a6fad5 commit d1faab4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ts/background/entity/stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class Stack<T extends Stringifible> {
private async _sync(): Promise<void> {
try {
const store = await this._storage.get(this._storageKey);
if (store.version < this._version) {
if (!store.version || store.version < this._version) {
await this._storage.set(this._storageKey, new StackInHouse<T>(this._version, this._stack));
} else if (store.version > this._version) {
console.log('[DEBUG] lost memory data, recovering from storage', this._version, '->', store.version);
Expand Down
8 changes: 2 additions & 6 deletions src/ts/background/repo/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ const { tabs, storage, commands, windows } = chrome;

export class Storage<T> {
get(key: string): Promise<T> {
return new Promise<T>((resolve) => {
storage.local.get(key, (value) => resolve(value as T));
});
return storage.local.get([key]).then(data => data[key] as T);
}

set(key: string, value: T): Promise<void> {
return new Promise<void>((resolve => {
storage.local.set({ [key]: value }, resolve);
}));
return storage.local.set({ [key]: value });
}
}

0 comments on commit d1faab4

Please sign in to comment.