From 8ad1498df6d55b2585a04a13c1e0da424e7b8ba2 Mon Sep 17 00:00:00 2001 From: beyondkmp Date: Mon, 28 Apr 2025 16:52:56 +0800 Subject: [PATCH] feat: update theme handling in ConfigManager and WindowService (#5433) - Change default theme return value to 'auto' in ConfigManager. - Adjust WindowService to set nativeTheme based on the updated theme configuration. --- src/main/services/ConfigManager.ts | 2 +- src/main/services/WindowService.ts | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/services/ConfigManager.ts b/src/main/services/ConfigManager.ts index 7123522ab1..86f23f80d2 100644 --- a/src/main/services/ConfigManager.ts +++ b/src/main/services/ConfigManager.ts @@ -37,7 +37,7 @@ export class ConfigManager { } getTheme(): ThemeMode { - return this.get(ConfigKeys.Theme, ThemeMode.light) + return this.get(ConfigKeys.Theme, ThemeMode.auto) } setTheme(theme: ThemeMode) { diff --git a/src/main/services/WindowService.ts b/src/main/services/WindowService.ts index 78e3574a63..f5d90de04d 100644 --- a/src/main/services/WindowService.ts +++ b/src/main/services/WindowService.ts @@ -2,7 +2,8 @@ import { is } from '@electron-toolkit/utils' import { isDev, isLinux, isMac, isWin } from '@main/constant' import { getFilesDir } from '@main/utils/file' import { IpcChannel } from '@shared/IpcChannel' -import { app, BrowserWindow, ipcMain, Menu, MenuItem, shell } from 'electron' +import { ThemeMode } from '@types' +import { app, BrowserWindow, ipcMain, Menu, MenuItem, nativeTheme, shell } from 'electron' import Logger from 'electron-log' import windowStateKeeper from 'electron-window-state' import { join } from 'path' @@ -47,6 +48,11 @@ export class WindowService { }) const theme = configManager.getTheme() + if (theme === ThemeMode.auto) { + nativeTheme.themeSource = 'system' + } else { + nativeTheme.themeSource = theme + } this.mainWindow = new BrowserWindow({ x: mainWindowState.x, @@ -61,8 +67,9 @@ export class WindowService { vibrancy: 'sidebar', visualEffectState: 'active', titleBarStyle: isLinux ? 'default' : 'hidden', - titleBarOverlay: theme === 'dark' ? titleBarOverlayDark : titleBarOverlayLight, - backgroundColor: isMac ? undefined : theme === 'dark' ? '#181818' : '#FFFFFF', + titleBarOverlay: nativeTheme.shouldUseDarkColors ? titleBarOverlayDark : titleBarOverlayLight, + backgroundColor: isMac ? undefined : nativeTheme.shouldUseDarkColors ? '#181818' : '#FFFFFF', + darkTheme: nativeTheme.shouldUseDarkColors, trafficLightPosition: { x: 8, y: 12 }, ...(isLinux ? { icon } : {}), webPreferences: {