-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathpreferences.mjs
46 lines (40 loc) · 1.21 KB
/
preferences.mjs
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
/*
* This file is provided by the webext-support repository at
* https://github.com/thunderbird/webext-support
*
* For usage descriptions, please check:
* https://github.com/thunderbird/webext-support/tree/master/modules/preferences
*
* Version 1.1
*
*/
const DEFAULTS = {
// Default preference values
enableDebug: false
}
// Return the current default values as an array of { prefName, defaultValue }
// objects.
export function getDefaults() {
return Object.entries(DEFAULTS).map(
e => ({ prefName: e[0], defaultValue: e[1]})
)
}
// Remove stored preference value.
export async function clearUserPref(name) {
await browser.storage.local.remove(name);
}
// Return preference value or default value.
export async function getPref(name) {
let defaultValue = DEFAULTS[name] ?? null;
let rv = await browser.storage.local.get({ [name]: defaultValue });
return rv[name];
}
// Ignore default values and return null if preference not set.
export async function getUserPref(name) {
let rv = await browser.storage.local.get({ [name]: null });
return rv[name];
}
// Set preference.
export async function setPref(name, value) {
await browser.storage.local.set({ [name]: value });
}