mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-23 10:00:08 +08:00
fix(ipc): enhance theme handling with title bar overlay updates and broadcast notifications (#5915)
feat(ipc): enhance theme handling with title bar overlay updates and broadcast notifications
This commit is contained in:
parent
d456b3d4ed
commit
341f744e07
@ -121,11 +121,21 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
|
|
||||||
// theme
|
// theme
|
||||||
ipcMain.handle(IpcChannel.App_SetTheme, (_, theme: ThemeMode) => {
|
ipcMain.handle(IpcChannel.App_SetTheme, (_, theme: ThemeMode) => {
|
||||||
|
const updateTitleBarOverlay = () => {
|
||||||
|
if (!mainWindow?.setTitleBarOverlay) return
|
||||||
|
const isDark = nativeTheme.shouldUseDarkColors
|
||||||
|
mainWindow.setTitleBarOverlay(isDark ? titleBarOverlayDark : titleBarOverlayLight)
|
||||||
|
}
|
||||||
|
|
||||||
|
const broadcastThemeChange = () => {
|
||||||
|
const isDark = nativeTheme.shouldUseDarkColors
|
||||||
|
const effectiveTheme = isDark ? ThemeMode.dark : ThemeMode.light
|
||||||
|
BrowserWindow.getAllWindows().forEach((win) => win.webContents.send(IpcChannel.ThemeChange, effectiveTheme))
|
||||||
|
}
|
||||||
|
|
||||||
const notifyThemeChange = () => {
|
const notifyThemeChange = () => {
|
||||||
const windows = BrowserWindow.getAllWindows()
|
updateTitleBarOverlay()
|
||||||
windows.forEach((win) =>
|
broadcastThemeChange()
|
||||||
win.webContents.send(IpcChannel.ThemeChange, nativeTheme.shouldUseDarkColors ? ThemeMode.dark : ThemeMode.light)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (theme === ThemeMode.auto) {
|
if (theme === ThemeMode.auto) {
|
||||||
@ -133,11 +143,10 @@ export function registerIpc(mainWindow: BrowserWindow, app: Electron.App) {
|
|||||||
nativeTheme.on('updated', notifyThemeChange)
|
nativeTheme.on('updated', notifyThemeChange)
|
||||||
} else {
|
} else {
|
||||||
nativeTheme.themeSource = theme
|
nativeTheme.themeSource = theme
|
||||||
nativeTheme.removeAllListeners('updated')
|
nativeTheme.off('updated', notifyThemeChange)
|
||||||
}
|
}
|
||||||
|
|
||||||
mainWindow?.setTitleBarOverlay &&
|
updateTitleBarOverlay()
|
||||||
mainWindow.setTitleBarOverlay(nativeTheme.shouldUseDarkColors ? titleBarOverlayDark : titleBarOverlayLight)
|
|
||||||
configManager.setTheme(theme)
|
configManager.setTheme(theme)
|
||||||
notifyThemeChange()
|
notifyThemeChange()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user