(De)serialize local history items the same as settings.

This commit is contained in:
Bauke 2022-03-20 22:06:11 +01:00
parent 0aa26aa809
commit c89156fe88
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 6 additions and 7 deletions

View File

@ -1,5 +1,7 @@
import browser from 'webextension-polyfill';
import {deserializeQueue, serializeQueue} from '../settings/migrations.js';
export class History {
public static async clear(): Promise<void> {
await browser.storage.local.remove('history');
@ -9,12 +11,7 @@ export class History {
const history = new History();
const stored = await browser.storage.local.get({history: []});
history.queue = stored.history as Queue.Item[];
// Initialize all the non-JSON values since they are stringified when saved.
for (const item of history.queue) {
item.added = new Date(item.added);
}
history.queue = deserializeQueue(stored.history);
return history;
}
@ -40,6 +37,8 @@ export class History {
}
public async save(): Promise<void> {
await browser.storage.local.set({history: this.queue});
await browser.storage.local.set({
history: serializeQueue(this.queue),
});
}
}