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.
This commit is contained in:
beyondkmp 2025-04-28 16:52:56 +08:00 committed by GitHub
parent 0a7bf424d2
commit 8ad1498df6
2 changed files with 11 additions and 4 deletions

View File

@ -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) {

View File

@ -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: {