Skip to content

Commit 0f0ecd7

Browse files
committed
Using local storage
1 parent 7ac499b commit 0f0ecd7

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

src/storage/local-storage.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { IStorage } from "./storage";
2+
import { StorageParams } from "./storage-params";
3+
import { Tab } from "./tab";
4+
import Browser from 'webextension-polyfill';
5+
6+
export class LocalStorage implements IStorage {
7+
getTabs(): Promise<Tab[]> {
8+
return new Promise(async resolve => {
9+
const { tabs } = await Browser.storage.local.get(StorageParams.TABS);
10+
if (tabs != undefined)
11+
return resolve(tabs);
12+
else resolve([]);
13+
});
14+
}
15+
16+
saveTabs(value: Tab[]): Promise<void> {
17+
return Browser.storage.local.set({ tabs: value });
18+
}
19+
20+
saveValue(name: StorageParams, value: object): Promise<void> {
21+
return Browser.storage.local.set({
22+
[name]: value
23+
});
24+
}
25+
26+
getValue(name: StorageParams): Promise<object> {
27+
return Browser.storage.local.get(name);
28+
}
29+
}

src/storage/storage-params.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export enum StorageParams {
2+
TABS = 'tabs',
3+
BLACK_LIST = 'black_list',
4+
RESTRICTION_LIST = 'restriction_list',
5+
NOTIFICATION_LIST = 'notification_list',
6+
NOTIFICATION_MESSAGE = 'notification_message',
7+
TIMEINTERVAL_LIST = 'time_interval',
8+
INTERVAL_INACTIVITY = 'inactivity_interval',
9+
INTERVAL_SAVE_STORAGE = 'interval_save_in_storage',
10+
INTERVAL_RANGE = 'range_days',
11+
DARK_MODE = 'night_mode',
12+
VIEW_TIME_IN_BADGE = 'view_time_in_badge',
13+
BLOCK_DEFERRAL = 'view_block_deferral',
14+
SHOW_HINT = 'show_hint',
15+
}

src/storage/storage.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { StorageParams } from "./storage-params";
2+
import { Tab } from "./tab";
3+
4+
export interface IStorage {
5+
getTabs(): Promise<Tab[]>;
6+
saveTabs(value:Tab[]): Promise<void>;
7+
saveValue(name:StorageParams, value: object): Promise<void>;
8+
getValue(name:StorageParams): Promise<object>;
9+
}

0 commit comments

Comments
 (0)