mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
💄 style: fix theme issue in desktop (#8380)
* 💄 style: fix theme issue
* fix
* fix
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
import { ElectronAppState, ThemeMode } from '@lobechat/electron-client-ipc';
|
||||
import { app, shell, systemPreferences } from 'electron';
|
||||
import { app, nativeTheme, shell, systemPreferences } from 'electron';
|
||||
import { macOS } from 'electron-is';
|
||||
import { readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import process from 'node:process';
|
||||
|
||||
import { DB_SCHEMA_HASH_FILENAME, LOCAL_DATABASE_DIR, userDataDir } from '@/const/dir';
|
||||
import { createLogger } from '@/utils/logger';
|
||||
|
||||
import { ControllerModule, ipcClientEvent, ipcServerEvent } from './index';
|
||||
|
||||
const logger = createLogger('controllers:SystemCtr');
|
||||
|
||||
export default class SystemController extends ControllerModule {
|
||||
private systemThemeListenerInitialized = false;
|
||||
|
||||
/**
|
||||
* Initialize system theme listener when app is ready
|
||||
*/
|
||||
afterAppReady() {
|
||||
this.initializeSystemThemeListener();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the 'getDesktopAppState' IPC request.
|
||||
* Gathers essential application and system information.
|
||||
@@ -26,6 +38,7 @@ export default class SystemController extends ControllerModule {
|
||||
isMac: platform === 'darwin',
|
||||
isWindows: platform === 'win32',
|
||||
platform: platform as 'darwin' | 'win32' | 'linux',
|
||||
systemAppearance: nativeTheme.shouldUseDarkColors ? 'dark' : 'light',
|
||||
userPath: {
|
||||
// User Paths (ensure keys match UserPathData / DesktopAppState interface)
|
||||
desktop: app.getPath('desktop'),
|
||||
@@ -100,4 +113,37 @@ export default class SystemController extends ControllerModule {
|
||||
private get DB_SCHEMA_HASH_PATH() {
|
||||
return join(this.app.appStoragePath, DB_SCHEMA_HASH_FILENAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize system theme listener to monitor OS theme changes
|
||||
*/
|
||||
private initializeSystemThemeListener() {
|
||||
if (this.systemThemeListenerInitialized) {
|
||||
logger.debug('System theme listener already initialized');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info('Initializing system theme listener');
|
||||
|
||||
// Get initial system theme
|
||||
const initialDarkMode = nativeTheme.shouldUseDarkColors;
|
||||
const initialSystemTheme: ThemeMode = initialDarkMode ? 'dark' : 'light';
|
||||
logger.info(`Initial system theme: ${initialSystemTheme}`);
|
||||
|
||||
// Listen for system theme changes
|
||||
nativeTheme.on('updated', () => {
|
||||
const isDarkMode = nativeTheme.shouldUseDarkColors;
|
||||
const systemTheme: ThemeMode = isDarkMode ? 'dark' : 'light';
|
||||
|
||||
logger.info(`System theme changed to: ${systemTheme}`);
|
||||
|
||||
// Broadcast system theme change to all renderer processes
|
||||
this.app.browserManager.broadcastToAllWindows('systemThemeChanged', {
|
||||
themeMode: systemTheme,
|
||||
});
|
||||
});
|
||||
|
||||
this.systemThemeListenerInitialized = true;
|
||||
logger.info('System theme listener initialized successfully');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user