Files
zn-ai/electron/service/theme-service/index.ts
duanshuwen 6615d11dd6 chore: restructure project and add i18n support
- Reorganize project structure with new electron and shared directories
- Add comprehensive i18n support with Chinese, English, and Japanese locales
- Update build configurations and TypeScript paths for new structure
- Add various UI components including chat interface and task management
- Include Windows release binaries and localization files
- Update dependencies and fix import paths throughout the codebase
2026-04-06 14:39:06 +08:00

62 lines
1.7 KiB
TypeScript

import { BrowserWindow, ipcMain, nativeTheme } from 'electron'
import { configManager } from '@electron/service/config-service'
import { logManager } from '@electron/service/logger'
import { IPC_EVENTS, CONFIG_KEYS } from '@lib/constants'
class ThemeService {
private static _instance: ThemeService;
private _isDark: boolean = nativeTheme.shouldUseDarkColors;
constructor() {
const themeMode = configManager.get(CONFIG_KEYS.THEME_MODE);
if (themeMode) {
nativeTheme.themeSource = themeMode;
this._isDark = nativeTheme.shouldUseDarkColors;
}
this._setupIpcEvent();
logManager.info('ThemeService initialized successfully.');
}
private _setupIpcEvent() {
ipcMain.handle(IPC_EVENTS.SET_THEME_MODE, (_e, mode: ThemeMode) => {
nativeTheme.themeSource = mode;
configManager.set(CONFIG_KEYS.THEME_MODE, mode);
return nativeTheme.shouldUseDarkColors;
});
ipcMain.handle(IPC_EVENTS.GET_THEME_MODE, () => {
return nativeTheme.themeSource;
});
ipcMain.handle(IPC_EVENTS.IS_DARK_THEME, () => {
return nativeTheme.shouldUseDarkColors;
});
nativeTheme.on('updated', () => {
this._isDark = nativeTheme.shouldUseDarkColors;
BrowserWindow.getAllWindows().forEach(win =>
win.webContents.send(IPC_EVENTS.THEME_MODE_UPDATED, this._isDark)
);
});
}
public static getInstance() {
if (!this._instance) {
this._instance = new ThemeService();
}
return this._instance;
}
public get isDark() {
return this._isDark;
}
public get themeMode() {
return nativeTheme.themeSource;
}
}
export const themeManager = ThemeService.getInstance();
export default themeManager;