feat: enhance theme management and image caching functionality
This commit is contained in:
@@ -14,6 +14,7 @@ const DEFAULT_CONFIG: IConfig = {
|
||||
[CONFIG_KEYS.PROVIDER]: '',
|
||||
[CONFIG_KEYS.DEFAULT_MODEL]: null,
|
||||
[CONFIG_KEYS.SELECTED_CHANNELS]: [],
|
||||
[CONFIG_KEYS.IMAGE_CACHE]: [],
|
||||
}
|
||||
|
||||
export class ConfigService {
|
||||
|
||||
@@ -8,15 +8,17 @@ class 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.');
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -25,7 +27,7 @@ class ThemeService {
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_EVENTS.GET_THEME_MODE, () => {
|
||||
return nativeTheme.themeSource;
|
||||
return configManager.get(CONFIG_KEYS.THEME_MODE);
|
||||
});
|
||||
|
||||
ipcMain.handle(IPC_EVENTS.IS_DARK_THEME, () => {
|
||||
|
||||
@@ -29,24 +29,26 @@ const isMac = process.platform === 'darwin';
|
||||
const isWindows = process.platform === 'win32';
|
||||
const useCustomTitleBar = isWindows;
|
||||
|
||||
const SHARED_WINDOW_OPTIONS = {
|
||||
frame: isMac || !useCustomTitleBar,
|
||||
titleBarStyle: isMac ? 'hiddenInset' : useCustomTitleBar ? 'hidden' : 'default',
|
||||
trafficLightPosition: isMac ? { x: 16, y: 16 } : undefined,
|
||||
show: false,
|
||||
title: 'NIANXX',
|
||||
darkTheme: themeManager.isDark,
|
||||
backgroundColor: themeManager.isDark ? '#2C2C2C' : '#FFFFFF',
|
||||
webPreferences: {
|
||||
nodeIntegration: false, // 禁用 Node.js 集成,提高安全性
|
||||
contextIsolation: true, // 启用上下文隔离,防止渲染进程访问主进程 API
|
||||
sandbox: true, // 启用沙箱模式,进一步增强安全性
|
||||
backgroundThrottling: false,
|
||||
preload: MAIN_WINDOW_VITE_DEV_SERVER_URL
|
||||
? path.join(process.cwd(), 'dist-electron/preload/preload.js')
|
||||
: path.join(__dirname, 'preload.js'),
|
||||
},
|
||||
} as BrowserWindowConstructorOptions;
|
||||
function getSharedWindowOptions(): BrowserWindowConstructorOptions {
|
||||
return {
|
||||
frame: isMac || !useCustomTitleBar,
|
||||
titleBarStyle: isMac ? 'hiddenInset' : useCustomTitleBar ? 'hidden' : 'default',
|
||||
trafficLightPosition: isMac ? { x: 16, y: 16 } : undefined,
|
||||
show: false,
|
||||
title: 'NIANXX',
|
||||
darkTheme: themeManager.isDark,
|
||||
backgroundColor: themeManager.isDark ? '#2C2C2C' : '#FFFFFF',
|
||||
webPreferences: {
|
||||
nodeIntegration: false, // 禁用 Node.js 集成,提高安全性
|
||||
contextIsolation: true, // 启用上下文隔离,防止渲染进程访问主进程 API
|
||||
sandbox: true, // 启用沙箱模式,进一步增强安全性
|
||||
backgroundThrottling: false,
|
||||
preload: MAIN_WINDOW_VITE_DEV_SERVER_URL
|
||||
? path.join(process.cwd(), 'dist-electron/preload/preload.js')
|
||||
: path.join(__dirname, 'preload.js'),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
class WindowService {
|
||||
private static _instance: WindowService;
|
||||
@@ -218,7 +220,7 @@ class WindowService {
|
||||
return this._isHiddenWin(name)
|
||||
? this._winStates[name].instance as BrowserWindow
|
||||
: new BrowserWindow({
|
||||
...SHARED_WINDOW_OPTIONS,
|
||||
...getSharedWindowOptions(),
|
||||
icon: this._logo,
|
||||
...opts,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user