blob: 76ff0f618f971a4d0a14e9af95d5ed40440daafa (
plain) (
blame)
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
|
import { useChromeStorageSync } from "use-chrome-storage";
export interface Settings {
apiKey: string;
apiKeyId?: string;
address: string;
}
export default function usePluginSettings() {
const [settings, setSettings, _1, _2, isInit] = useChromeStorageSync(
"settings",
{
apiKey: "",
address: "",
} as Settings,
);
return { settings, setSettings, isPending: isInit };
}
export async function getPluginSettings() {
return (await chrome.storage.sync.get("settings")).settings as Settings;
}
export function subscribeToSettingsChanges(
callback: (settings: Settings) => void,
) {
chrome.storage.sync.onChanged.addListener((changes) => {
if (changes.settings === undefined) {
return;
}
callback(changes.settings.newValue as Settings);
});
}
|