Skip to content

The swiss army knife of lossless video/audio editing

Apply theme after app ready and keep window background in sync

Claude93e943129998
diff --git a/src/main/index.ts b/src/main/index.ts
index d7c10ec8..47385c39 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -156,6 +156,8 @@ function getSavedBounds() {
};
}
+const getBackgroundColor = () => (nativeTheme.shouldUseDarkColors ? '#333' : '#fff');
+
function createWindow() {
const savedBounds = getSavedBounds();
@@ -169,7 +171,7 @@ function createWindow() {
webSecurity: !isDev,
preload: fileURLToPath(new URL('../preload/index.cjs', import.meta.url)),
},
- backgroundColor: nativeTheme.shouldUseDarkColors ? '#333' : '#fff',
+ backgroundColor: getBackgroundColor(),
minWidth: 300,
minHeight: 300,
});
@@ -301,11 +303,6 @@ async function init() {
await configStore.init({ customConfigDir: argv['configDir'] });
logger.info('Initialized config store');
- // https://www.electronjs.org/docs/latest/tutorial/dark-mode
- // also affects what `prefers-color-scheme` reports in the renderer
- nativeTheme.themeSource = configStore.get('theme');
- configStore.onDidChange('theme', (theme) => { nativeTheme.themeSource = theme; });
-
const allowMultipleInstances = configStore.get('allowMultipleInstances');
const language = configStore.get('language');
@@ -392,6 +389,12 @@ async function init() {
logger.info('Waiting for app to become ready');
await readyPromise;
+ // https://www.electronjs.org/docs/latest/tutorial/dark-mode
+ // also affects what `prefers-color-scheme` reports in the renderer
+ nativeTheme.themeSource = configStore.get('theme');
+ configStore.onDidChange('theme', (theme) => { nativeTheme.themeSource = theme; });
+ nativeTheme.on('updated', () => mainWindow?.setBackgroundColor(getBackgroundColor()));
+
logger.info('CLI arguments', argv);
if (argv['keyboardAction']) logger.warn('--keyboard-action only works with an already running instance (and "Allow multiple instances" disabled), ignoring it and its arguments');
// Only if no files to open already (open-file might have already added some files)
diff --git a/src/renderer/src/hooks/useUserSettingsRoot.ts b/src/renderer/src/hooks/useUserSettingsRoot.ts
index b1a9a210..16886eb6 100644
--- a/src/renderer/src/hooks/useUserSettingsRoot.ts
+++ b/src/renderer/src/hooks/useUserSettingsRoot.ts
@@ -18,6 +18,7 @@ function subscribeSystemDarkMode(onChange: () => void) {
darkModeMediaQuery.addEventListener('change', onChange);
return () => darkModeMediaQuery.removeEventListener('change', onChange);
}
+const resolveDarkMode = (theme: Config['theme'], systemDarkMode: boolean) => (theme === 'system' ? systemDarkMode : theme === 'dark');
export default function useUserSettingsRoot() {
const firstUpdateRef = useRef(true);
@@ -220,9 +221,9 @@ export default function useUserSettingsRoot() {
// note: main sets nativeTheme.themeSource from `theme`, and it must be 'system' for prefers-color-scheme to report the OS theme
const systemDarkMode = useSyncExternalStore(subscribeSystemDarkMode, () => darkModeMediaQuery.matches);
- const darkMode = theme === 'system' ? systemDarkMode : theme === 'dark';
+ const darkMode = resolveDarkMode(theme, systemDarkMode);
- const toggleDarkMode = useCallback(() => setTheme(darkMode ? 'light' : 'dark'), [darkMode]);
+ const toggleDarkMode = useCallback(() => setTheme((t) => (resolveDarkMode(t, darkModeMediaQuery.matches) ? 'light' : 'dark')), []);
const prefersReducedMotion = useMemo(() => {
if (reducedMotion !== 'user') return reducedMotion === 'always';