feat: add provider API service for managing provider accounts and keys feat: create provider runtime sync service for agent runtime management feat: introduce script execution service for running automation scripts feat: develop script store service for managing script metadata and storage feat: implement theme service for managing application theme settings feat: add updater service for handling application updates feat: create window service for managing application windows and their states
64 lines
1.8 KiB
TypeScript
64 lines
1.8 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 '@runtime/lib/constants'
|
|
|
|
class ThemeService {
|
|
private static _instance: ThemeService;
|
|
private _isDark: boolean = nativeTheme.shouldUseDarkColors;
|
|
|
|
constructor() {
|
|
this._setupIpcEvent();
|
|
logManager.info('ThemeService initialized successfully.');
|
|
}
|
|
|
|
async init() {
|
|
const themeMode = configManager.get(CONFIG_KEYS.THEME_MODE);
|
|
nativeTheme.themeSource = themeMode;
|
|
this._isDark = nativeTheme.shouldUseDarkColors;
|
|
logManager.info('ThemeService async init completed.');
|
|
}
|
|
|
|
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 configManager.get(CONFIG_KEYS.THEME_MODE);
|
|
});
|
|
|
|
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;
|