From ce1ae208d1ca4f86e750fbbb18b8d3aa89a599d8 Mon Sep 17 00:00:00 2001 From: Addison Beck Date: Fri, 28 Jan 2022 11:30:45 -0500 Subject: [PATCH] [bug] Update theme.js to refelect new storage structure (#1416) * [bug] Update theme.js to refelect new storage structure * [bug] Remove unecassary defaults --- src/app/settings/options.component.ts | 4 ++-- src/theme.js | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/settings/options.component.ts b/src/app/settings/options.component.ts index 6f384d66..996ea8bb 100644 --- a/src/app/settings/options.component.ts +++ b/src/app/settings/options.component.ts @@ -19,7 +19,7 @@ export class OptionsComponent implements OnInit { disableIcons: boolean; enableGravatars: boolean; enableFullWidth: boolean; - theme: ThemeType = ThemeType.Light; + theme: ThemeType; locale: string; vaultTimeouts: { name: string; value: number }[]; localeOptions: any[]; @@ -28,7 +28,7 @@ export class OptionsComponent implements OnInit { vaultTimeout: FormControl = new FormControl(null); private startingLocale: string; - private startingTheme: ThemeType = ThemeType.Light; + private startingTheme: ThemeType; constructor( private stateService: StateService, diff --git a/src/theme.js b/src/theme.js index 7f94db8b..3fa49c6b 100644 --- a/src/theme.js +++ b/src/theme.js @@ -6,17 +6,16 @@ const htmlEl = document.documentElement; let theme = defaultTheme; - const stateJson = window.localStorage.getItem("state"); - if (stateJson != null) { - const globals = JSON.parse(stateJson).globals; - if (globals != null && globals.theme != null) { - if (globals.theme.indexOf("system") > -1) { + const globalState = window.localStorage.getItem("global"); + if (globalState != null) { + const globalStateJson = JSON.parse(globalState); + if (globalStateJson != null && globalStateJson.theme != null) { + if (globalStateJson.theme.indexOf("system") > -1) { theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; - } else if (globals.theme.indexOf("dark") > -1) { + } else if (globalStateJson.theme.indexOf("dark") > -1) { theme = "dark"; } } - if (!htmlEl.classList.contains("theme_" + theme)) { htmlEl.classList.remove("theme_" + defaultTheme); htmlEl.classList.add("theme_" + theme);