-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
storage.ts
50 lines (44 loc) · 1.16 KB
/
storage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import browser from 'webextension-polyfill';
import ICloudClient from './iCloudClient';
import { PopupState } from './pages/Popup/stateMachine';
export type Autofill = {
button: boolean;
contextMenu: boolean;
};
export type Options = {
autofill: Autofill;
};
export type Store = {
popupState: PopupState;
iCloudHmeOptions: Options; // TODO: rename key to options
clientState?: {
setupUrl: ConstructorParameters<typeof ICloudClient>[0];
webservices: ConstructorParameters<typeof ICloudClient>[1];
};
};
export const DEFAULT_STORE = {
popupState: PopupState.SignedOut,
iCloudHmeOptions: {
autofill: {
button: true,
contextMenu: true,
},
},
clientState: undefined,
};
export async function getBrowserStorageValue<K extends keyof Store>(
key: K
): Promise<Store[K] | undefined> {
const store: Partial<Store> = await browser.storage.local.get(key);
return store[key];
}
export async function setBrowserStorageValue<K extends keyof Store>(
key: K,
value: Store[K]
): Promise<void> {
if (value === undefined) {
await browser.storage.local.remove(key);
} else {
await browser.storage.local.set({ [key]: value });
}
}