forked from wong2/chatgpt-google-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.ts
48 lines (40 loc) · 1.15 KB
/
config.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
import { defaults } from 'lodash-es'
import Browser from 'webextension-polyfill'
export enum TriggerMode {
Always = 'always',
QuestionMark = 'questionMark',
Manually = 'manually',
}
export const TRIGGER_MODE_TEXT = {
[TriggerMode.Always]: 'Always',
[TriggerMode.QuestionMark]: 'When query ends with question mark (?)',
[TriggerMode.Manually]: 'Manually',
}
export enum Theme {
Auto = 'auto',
Light = 'light',
Dark = 'dark',
}
export enum Language {
Auto = 'auto',
English = 'english',
Chinese = 'chinese',
Spanish = 'spanish',
French = 'french',
Korean = 'korean',
Japanese = 'japanese',
}
const userConfigWithDefaultValue = {
triggerMode: TriggerMode.Always,
theme: Theme.Auto,
language: Language.Auto,
}
export type UserConfig = typeof userConfigWithDefaultValue
export async function getUserConfig(): Promise<UserConfig> {
const result = await Browser.storage.local.get(Object.keys(userConfigWithDefaultValue))
return defaults(result, userConfigWithDefaultValue)
}
export async function updateUserConfig(updates: Partial<UserConfig>) {
console.debug('update configs', updates)
return Browser.storage.local.set(updates)
}