@@ -4,17 +4,18 @@ import { updateIcon } from './actionIcon.js'
4
4
5
5
export const KEY_DISABLED_HOSTS = 'disabled_hosts'
6
6
export const KEY_RESIZABLE_STATE = 'resizable_state'
7
+ export const KEY_THEME = 'theme'
7
8
8
9
// Listens to changes on the storage. Updates disabled hosts list, if stored list changes
9
10
/** @type {string[] } */
10
11
export let disabledHosts = await getDisabledHosts ( )
11
12
export let resizableState = await getResizableState ( )
13
+ export let theme = await getTheme ( )
12
14
13
15
storage . local . onChanged . addListener ( ( changes ) => {
14
- if ( KEY_DISABLED_HOSTS in changes ) {
15
- disabledHosts = changes [ KEY_DISABLED_HOSTS ] . newValue ?? [ ]
16
- }
16
+ if ( KEY_DISABLED_HOSTS in changes ) disabledHosts = changes [ KEY_DISABLED_HOSTS ] . newValue ?? [ ]
17
17
if ( KEY_RESIZABLE_STATE in changes ) resizableState = changes [ KEY_RESIZABLE_STATE ] . newValue ?? false
18
+ if ( KEY_THEME in changes ) theme = changes [ KEY_THEME ] . newValue ?? 'system'
18
19
} )
19
20
20
21
/**
@@ -29,6 +30,10 @@ async function getResizableState() {
29
30
return ( await storage . local . get ( KEY_RESIZABLE_STATE ) ) [ KEY_RESIZABLE_STATE ] ?? false
30
31
}
31
32
33
+ async function getTheme ( ) {
34
+ return ( await storage . local . get ( KEY_THEME ) ) [ KEY_THEME ] ?? 'system'
35
+ }
36
+
32
37
/**
33
38
* Async function to invert the state of a hostname.
34
39
* Adds new entry if not disabled, removes entry, if already disabled
@@ -54,6 +59,12 @@ export async function setResizableState(state) {
54
59
} ) )
55
60
}
56
61
62
+ export async function setTheme ( state ) {
63
+ return ( await storage . local . set ( {
64
+ [ KEY_THEME ] : state
65
+ } ) )
66
+ }
67
+
57
68
/**
58
69
* Retrieves the hostname from a URL
59
70
* @param {string } url Full URL string
0 commit comments