@@ -4,17 +4,18 @@ import { updateIcon } from './actionIcon.js'
44
55export const KEY_DISABLED_HOSTS = 'disabled_hosts'
66export const KEY_RESIZABLE_STATE = 'resizable_state'
7+ export const KEY_THEME = 'theme'
78
89// Listens to changes on the storage. Updates disabled hosts list, if stored list changes
910/** @type {string[] } */
1011export let disabledHosts = await getDisabledHosts ( )
1112export let resizableState = await getResizableState ( )
13+ export let theme = await getTheme ( )
1214
1315storage . 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 ?? [ ]
1717 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'
1819} )
1920
2021/**
@@ -29,6 +30,10 @@ async function getResizableState() {
2930 return ( await storage . local . get ( KEY_RESIZABLE_STATE ) ) [ KEY_RESIZABLE_STATE ] ?? false
3031}
3132
33+ async function getTheme ( ) {
34+ return ( await storage . local . get ( KEY_THEME ) ) [ KEY_THEME ] ?? 'system'
35+ }
36+
3237/**
3338 * Async function to invert the state of a hostname.
3439 * Adds new entry if not disabled, removes entry, if already disabled
@@ -54,6 +59,12 @@ export async function setResizableState(state) {
5459 } ) )
5560}
5661
62+ export async function setTheme ( state ) {
63+ return ( await storage . local . set ( {
64+ [ KEY_THEME ] : state
65+ } ) )
66+ }
67+
5768/**
5869 * Retrieves the hostname from a URL
5970 * @param {string } url Full URL string
0 commit comments