mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 19:30:17 +08:00
* refactor(IpcChannel): rename theme change event and streamline theme handling - Updated the IpcChannel enum to rename 'theme:change' to 'theme:updated' for clarity. - Refactored theme handling in ipc.ts to utilize a new ThemeService, simplifying theme updates and event broadcasting. - Adjusted various components to consistently use the updated theme variable naming convention. * refactor(Theme): standardize theme handling across components - Updated theme retrieval to use 'actualTheme' instead of 'theme' for consistency. - Changed default theme setting from 'auto' to 'system' in ConfigManager and related components. - Adjusted theme handling in various components to reflect the new naming convention and ensure proper theme application. * fix(Theme): improve theme handling and migration logic - Added a console log for debugging theme transitions in ThemeProvider. - Updated ThemeService to ensure theme is set correctly when changed. - Incremented version number in store configuration to reflect changes. - Enhanced migration logic to convert 'auto' theme setting to 'system' for better consistency. * feat(Theme): add getTheme IPC channel and improve theme management - Introduced a new IPC channel 'App_GetTheme' to retrieve the current theme. - Updated ThemeService to include a method for getting the current theme. - Refactored theme initialization in WindowService to ensure proper theme setup. - Enhanced theme handling in various components to utilize the new theme retrieval method. * fix(ThemeService): improve theme initialization and retrieval logic - Set default theme to 'system' and updated theme initialization to handle legacy versions. - Enhanced getTheme method to return both the current theme and the actual theme based on nativeTheme settings. - Removed redundant initTheme method from ThemeService and ensured themeService is imported in WindowService for proper initialization. - Updated ThemeProvider to handle the new structure of the theme retrieval response. * refactor(Settings): remove theme management from settings - Eliminated theme-related state and actions from the settings slice. - Updated useSettings hook to remove theme handling functionality. - Cleaned up imports by removing unused ThemeMode type. * refactor(Theme): update theme retrieval in GeneralSettings and HomeWindow - Restored theme retrieval in GeneralSettings and HomeWindow components. - Adjusted imports to ensure proper theme management. - Updated theme condition checks to utilize the ThemeMode enumeration for consistency. * refactor(Theme): update theme terminology and retrieval in Sidebar and DisplaySettings - Changed theme label from 'auto' to 'system' in multiple localization files for consistency. - Updated Sidebar component to reflect the new theme terminology. - Adjusted DisplaySettings to display the updated theme label. * refactor(ThemeProvider): initialize theme state from API response * refactor(ThemeProvider): reset theme state to default values and streamline initialization logic * refactor(Theme): enhance theme management by incorporating 'system' mode and updating state handling - Updated ThemeService to include 'system' as a valid theme option. - Refactored ThemeProvider to utilize useSettings for theme state management and ensure proper initialization. - Adjusted useSettings to include theme setting functionality. - Modified settings slice to manage theme state effectively. * refactor(WindowService, ThemeProvider, Messages, HomeWindow): streamline imports and clean up unused variables - Removed duplicate import of ThemeService in WindowService. - Adjusted import order in ThemeProvider for clarity. - Simplified useSettings destructuring in Messages component. - Cleaned up unused ThemeMode import in HomeWindow. * refactor(Theme): standardize theme usage across components by replacing 'actualTheme' with 'theme' - Updated components to consistently use 'theme' instead of 'actualTheme' for better clarity and maintainability. - Adjusted ThemeProvider to reflect changes in theme state management. - Ensured all relevant components are aligned with the new theme structure. * refactor(Theme): remove unused theme retrieval functionality - Eliminated the App_GetTheme channel and associated methods from ThemeService and IPC handling. - Updated components to use the new theme structure, replacing 'actualTheme' with 'settedTheme' for consistency. - Ensured all theme-related functionalities are streamlined and aligned with the latest changes. * refactor(Theme): update theme variable usage in ChatFlowHistory and GeneralSettings - Replaced 'theme' with 'settedTheme' in ChatFlowHistory for consistency with recent theme structure changes. - Simplified theme destructuring in GeneralSettings by removing unused 'themeMode' variable. - Ensured alignment with the latest theme management updates across components. * refactor(Theme): update theme variable in GeneralSettings component - Replaced 'themeMode' with 'theme' in GeneralSettings for consistency with recent theme structure changes. - Ensured alignment with the latest theme management updates across components. --------- Co-authored-by: beyondkmp <beyondkmkp@gmail.com>
49 lines
1.6 KiB
TypeScript
49 lines
1.6 KiB
TypeScript
import { IpcChannel } from '@shared/IpcChannel'
|
|
import { ThemeMode } from '@types'
|
|
import { BrowserWindow, nativeTheme } from 'electron'
|
|
|
|
import { titleBarOverlayDark, titleBarOverlayLight } from '../config'
|
|
import { configManager } from './ConfigManager'
|
|
|
|
class ThemeService {
|
|
private theme: ThemeMode = ThemeMode.system
|
|
constructor() {
|
|
this.theme = configManager.getTheme()
|
|
|
|
if (this.theme === ThemeMode.dark || this.theme === ThemeMode.light || this.theme === ThemeMode.system) {
|
|
nativeTheme.themeSource = this.theme
|
|
} else {
|
|
// 兼容旧版本
|
|
configManager.setTheme(ThemeMode.system)
|
|
nativeTheme.themeSource = ThemeMode.system
|
|
}
|
|
nativeTheme.on('updated', this.themeUpdatadHandler.bind(this))
|
|
}
|
|
|
|
themeUpdatadHandler() {
|
|
BrowserWindow.getAllWindows().forEach((win) => {
|
|
if (win && !win.isDestroyed() && win.setTitleBarOverlay) {
|
|
try {
|
|
win.setTitleBarOverlay(nativeTheme.shouldUseDarkColors ? titleBarOverlayDark : titleBarOverlayLight)
|
|
} catch (error) {
|
|
// don't throw error if setTitleBarOverlay failed
|
|
// Because it may be called with some windows have some title bar
|
|
}
|
|
}
|
|
win.webContents.send(IpcChannel.ThemeUpdated, nativeTheme.shouldUseDarkColors ? ThemeMode.dark : ThemeMode.light)
|
|
})
|
|
}
|
|
|
|
setTheme(theme: ThemeMode) {
|
|
if (theme === this.theme) {
|
|
return
|
|
}
|
|
|
|
this.theme = theme
|
|
nativeTheme.themeSource = theme
|
|
configManager.setTheme(theme)
|
|
}
|
|
}
|
|
|
|
export const themeService = new ThemeService()
|