diff --git a/src/public/app/desktop.ts b/src/public/app/desktop.ts index b78074126..b546bf68c 100644 --- a/src/public/app/desktop.ts +++ b/src/public/app/desktop.ts @@ -50,6 +50,7 @@ function initOnElectron() { const currentWindow = electronRemote.getCurrentWindow(); const style = window.getComputedStyle(document.body); + initDarkOrLightMode(style); initTransparencyEffects(style, currentWindow); if (options.get("nativeTitleBarVisible") !== "true") { @@ -91,3 +92,21 @@ function initTransparencyEffects(style: CSSStyleDeclaration, currentWindow: Elec } } } + +/** + * Informs Electron that we prefer a dark or light theme. Apart from changing prefers-color-scheme at CSS level which is a side effect, + * this fixes color issues with background effects or native title bars. + * + * @param style the root CSS element to read variables from. + */ +function initDarkOrLightMode(style: CSSStyleDeclaration) { + let themeSource: typeof nativeTheme.themeSource = "system"; + + const themeStyle = style.getPropertyValue("--theme-style"); + if (style.getPropertyValue("--theme-style-auto") !== "true" && (themeStyle === "light" || themeStyle === "dark")) { + themeSource = themeStyle; + } + + const { nativeTheme } = utils.dynamicRequire("@electron/remote") as typeof ElectronRemote; + nativeTheme.themeSource = themeSource; +} diff --git a/src/public/stylesheets/theme-next.css b/src/public/stylesheets/theme-next.css index c740a3006..1c8a7d810 100644 --- a/src/public/stylesheets/theme-next.css +++ b/src/public/stylesheets/theme-next.css @@ -5,3 +5,7 @@ /* Import the dark color scheme when the system preference is set to dark mode */ @import url(./theme-next-dark.css) (prefers-color-scheme: dark); + +:root { + --theme-style-auto: true; +} diff --git a/src/public/stylesheets/theme.css b/src/public/stylesheets/theme.css index 35a22e516..6b8fee32d 100644 --- a/src/public/stylesheets/theme.css +++ b/src/public/stylesheets/theme.css @@ -5,3 +5,7 @@ /* Import the dark color scheme when the system preference is set to dark mode */ @import url(./theme-dark.css) (prefers-color-scheme: dark); + +:root { + --theme-style-auto: true; +} \ No newline at end of file