2022-03-05 13:10:45 +00:00
|
|
|
import browser from 'webextension-polyfill';
|
|
|
|
|
2022-03-20 21:06:11 +00:00
|
|
|
import {deserializeQueue, serializeQueue} from '../settings/migrations.js';
|
|
|
|
|
2022-03-05 13:10:45 +00:00
|
|
|
export class History {
|
|
|
|
public static async clear(): Promise<void> {
|
|
|
|
await browser.storage.local.remove('history');
|
|
|
|
}
|
|
|
|
|
|
|
|
public static async fromLocalStorage(): Promise<History> {
|
|
|
|
const history = new History();
|
|
|
|
|
|
|
|
const stored = await browser.storage.local.get({history: []});
|
2022-03-20 21:06:11 +00:00
|
|
|
history.queue = deserializeQueue(stored.history);
|
2022-03-05 13:10:45 +00:00
|
|
|
|
|
|
|
return history;
|
|
|
|
}
|
|
|
|
|
|
|
|
public queue: Queue.Item[];
|
|
|
|
|
|
|
|
private constructor() {
|
|
|
|
this.queue = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
public async clear(): Promise<void> {
|
|
|
|
await History.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async insertItems(items: Queue.Item[]): Promise<void> {
|
|
|
|
this.queue = this.queue.concat(items);
|
|
|
|
|
|
|
|
for (const [index, item] of this.queue.entries()) {
|
|
|
|
item.id = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
await this.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
public async save(): Promise<void> {
|
2022-03-20 21:06:11 +00:00
|
|
|
await browser.storage.local.set({
|
|
|
|
history: serializeQueue(this.queue),
|
|
|
|
});
|
2022-03-05 13:10:45 +00:00
|
|
|
}
|
|
|
|
}
|