Skip to content

The swiss army knife of lossless video/audio editing

Add theme setting that can follow the OS

Claudea159e2ef1d8a
diff --git a/locales/en/translation.json b/locales/en/translation.json
index 7488aefb..656f6e66 100644
--- a/locales/en/translation.json
+++ b/locales/en/translation.json
@@ -174,6 +174,7 @@
"Cut mode": "Cut mode",
"Cutlist": "Cutlist",
"Cutpoints may be inaccurate.": "Cutpoints may be inaccurate.",
+ "Dark": "Dark",
"Data": "Data",
"DaVinci Resolve / Final Cut Pro XML": "DaVinci Resolve / Final Cut Pro XML",
"Decimate allows you to losslessly extract only the keyframes from a video, discarding all non-keyframes. You can also optionally drop some of the keyframes. This can dramatically speed up playback and is useful for shortening long videos with little motion, such as creating time-lapse videos.": "Decimate allows you to losslessly extract only the keyframes from a video, discarding all non-keyframes. You can also optionally drop some of the keyframes. This can dramatically speed up playback and is useful for shortening long videos with little motion, such as creating time-lapse videos.",
@@ -444,6 +445,7 @@
"Left": "Left",
"Less than 2 frames found": "Less than 2 frames found",
"Licenses": "Licenses",
+ "Light": "Light",
"Load overview": "Load overview",
"Load segments from the new file, but keep the current media": "Load segments from the new file, but keep the current media",
"Loaded existing preview file: {{ fileName }}": "Loaded existing preview file: {{ fileName }}",
@@ -778,6 +780,7 @@
"The size of the merged output file ({{outputFileTotalSize}}) differs from the total size of source files ({{sourceFilesTotalSize}}) by more than {{maxDiffPercent}}%. This could indicate that there was a problem during the merge.": "The size of the merged output file ({{outputFileTotalSize}}) differs from the total size of source files ({{sourceFilesTotalSize}}) by more than {{maxDiffPercent}}%. This could indicate that there was a problem during the merge.",
"The video inside segments will be discarded, while the video surrounding them will be kept.": "The video inside segments will be discarded, while the video surrounding them will be kept.",
"The video inside segments will be kept, while the video outside will be discarded.": "The video inside segments will be kept, while the video outside will be discarded.",
+ "Theme": "Theme",
"There is a known issue in FFmpeg with cutting FLAC files. The file will be re-encoded, which is still lossless, but the export may be slower.": "There is a known issue in FFmpeg with cutting FLAC files. The file will be re-encoded, which is still lossless, but the export may be slower.",
"There is a known issue with cutting iPhone HEVC videos. The output file may not work in all players.": "There is a known issue with cutting iPhone HEVC videos. The output file may not work in all players.",
"There is a known problem with this file type, and the output might not be playable. You can work around this problem by enabling the \"Experimental flag\" under Settings.": "There is a known problem with this file type, and the output might not be playable. You can work around this problem by enabling the \"Experimental flag\" under Settings.",
diff --git a/src/common/types.ts b/src/common/types.ts
index 0354db8f..bdef8db8 100644
--- a/src/common/types.ts
+++ b/src/common/types.ts
@@ -115,7 +115,7 @@ export const configSchema = z.object({
trashTmpFiles: z.boolean(), askForCleanup: z.boolean(), closeFile: z.boolean(), cleanupAfterExport: z.boolean().or(z.undefined()).exactOptional(),
}),
allowMultipleInstances: z.boolean(),
- darkMode: z.boolean(),
+ theme: z.enum(['dark', 'light', 'system']),
preferStrongColors: z.boolean(),
outputFileNameMinZeroPadding: z.number(),
cutFromAdjustmentFrames: z.number(),
diff --git a/src/main/configStore.ts b/src/main/configStore.ts
index 58a495de..656bdb28 100644
--- a/src/main/configStore.ts
+++ b/src/main/configStore.ts
@@ -160,7 +160,7 @@ const defaults: Config = {
trashTmpFiles: true, askForCleanup: true, closeFile: true, cleanupAfterExport: false,
},
allowMultipleInstances: false,
- darkMode: true,
+ theme: 'dark',
preferStrongColors: false,
outputFileNameMinZeroPadding: 1,
cutFromAdjustmentFrames: 0,
@@ -257,6 +257,13 @@ export async function init({ customConfigDir }: { customConfigDir: string | unde
set('treatOutputFileModifiedTimeAsStart', enableTransferTimestamps ? true : undefined);
}
+ const darkMode = store.get('darkMode'); // todo remove after a while
+ if (darkMode != null) {
+ logger.info('Migrating darkMode to theme');
+ store.delete('darkMode');
+ set('theme', darkMode ? 'dark' : 'light');
+ }
+
const cleanupChoices = store.get('cleanupChoices'); // todo remove after a while
if (cleanupChoices != null && cleanupChoices.closeFile == null) {
logger.info('Migrating cleanupChoices.closeFile');
diff --git a/src/main/index.ts b/src/main/index.ts
index 7f7ea388..7532b534 100644
--- a/src/main/index.ts
+++ b/src/main/index.ts
@@ -157,10 +157,8 @@ function getSavedBounds() {
}
function createWindow() {
- const darkMode = configStore.get('darkMode');
- // todo follow darkMode setting when user switches
// https://www.electronjs.org/docs/latest/tutorial/dark-mode
- if (darkMode) nativeTheme.themeSource = 'dark';
+ nativeTheme.themeSource = configStore.get('theme');
const savedBounds = getSavedBounds();
@@ -174,7 +172,7 @@ function createWindow() {
webSecurity: !isDev,
preload: fileURLToPath(new URL('../preload/index.cjs', import.meta.url)),
},
- backgroundColor: darkMode ? '#333' : '#fff',
+ backgroundColor: nativeTheme.shouldUseDarkColors ? '#333' : '#fff',
minWidth: 300,
minHeight: 300,
});
@@ -455,6 +453,11 @@ function quitApp() {
const setProgressBar = (v: number) => mainWindow?.setProgressBar(v);
+// also affects what `prefers-color-scheme` reports in the renderer
+function setThemeSource(theme: Config['theme']) {
+ nativeTheme.themeSource = theme;
+}
+
function sendOsNotification(options: NotificationConstructorOptions) {
if (!Notification.isSupported()) return;
const notification = new Notification(options);
@@ -471,6 +474,7 @@ const remoteApi = {
focusWindow,
quitApp,
setProgressBar,
+ setThemeSource,
sendOsNotification,
writeClipboardText: (text: string) => electron.clipboard.writeText(text),
readClipboardText: () => electron.clipboard.readText(),
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 1beb4e0e..6e77c992 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -191,8 +191,8 @@ function App() {
const [selectedBatchFiles, setSelectedBatchFiles] = useState<string[]>([]);
const allUserSettings = useUserSettingsRoot();
- const { captureFormat, keyframeCut, preserveMetadata, preserveMetadataOnMerge, preserveMovData, preserveChapters, movFastStart, avoidNegativeTs, autoMerge, timecodeFormat, invertCutSegments, autoExportExtraStreams, askBeforeClose, enableImportChapters, enableAskForFileOpenAction, playbackVolume, autoSaveProjectFile, wheelSensitivity, waveformHeight, invertTimelineScroll, language, ffmpegExperimental, hideNotifications, hideOsNotifications, autoLoadTimecode, autoDeleteMergedSegments, exportConfirmEnabled, segmentsToChapters, simpleMode, cutFileTemplate, cutMergedFileTemplate, mergedFileTemplate, keyboardSeekAccFactor, keyboardNormalSeekSpeed, keyboardSeekSpeed2, keyboardSeekSpeed3, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, outFormatLocked, safeOutputFileName, enableAutoHtml5ify, segmentsToChaptersOnly, keyBindings, enableSmartCut, customFfPath, storeProjectInWorkingDir, enableOverwriteOutput, mouseWheelZoomModifierKey, mouseWheelFrameSeekModifierKey, mouseWheelKeyframeSeekModifierKey, captureFrameMethod, captureFrameQuality, captureFrameFileNameFormat, enableNativeHevc, cleanupChoices, darkMode, preferStrongColors, outputFileNameMinZeroPadding, cutFromAdjustmentFrames, cutToAdjustmentFrames, waveformMode: waveformModePreference, thumbnailsEnabled, keyframesEnabled, reducedMotion, ffmpegHwaccel } = allUserSettings.settings;
- const { setCaptureFormat, setCustomOutDir, setKeyframeCut, setPlaybackVolume, setExportConfirmEnabled, setSimpleMode, setOutFormatLocked, setSafeOutputFileName, setKeyBindings, resetKeyBindings, setStoreProjectInWorkingDir, setCleanupChoices, toggleDarkMode, setWaveformMode, setThumbnailsEnabled, setKeyframesEnabled, prefersReducedMotion, customOutDir } = allUserSettings;
+ const { captureFormat, keyframeCut, preserveMetadata, preserveMetadataOnMerge, preserveMovData, preserveChapters, movFastStart, avoidNegativeTs, autoMerge, timecodeFormat, invertCutSegments, autoExportExtraStreams, askBeforeClose, enableImportChapters, enableAskForFileOpenAction, playbackVolume, autoSaveProjectFile, wheelSensitivity, waveformHeight, invertTimelineScroll, language, ffmpegExperimental, hideNotifications, hideOsNotifications, autoLoadTimecode, autoDeleteMergedSegments, exportConfirmEnabled, segmentsToChapters, simpleMode, cutFileTemplate, cutMergedFileTemplate, mergedFileTemplate, keyboardSeekAccFactor, keyboardNormalSeekSpeed, keyboardSeekSpeed2, keyboardSeekSpeed3, treatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, outFormatLocked, safeOutputFileName, enableAutoHtml5ify, segmentsToChaptersOnly, keyBindings, enableSmartCut, customFfPath, storeProjectInWorkingDir, enableOverwriteOutput, mouseWheelZoomModifierKey, mouseWheelFrameSeekModifierKey, mouseWheelKeyframeSeekModifierKey, captureFrameMethod, captureFrameQuality, captureFrameFileNameFormat, enableNativeHevc, cleanupChoices, preferStrongColors, outputFileNameMinZeroPadding, cutFromAdjustmentFrames, cutToAdjustmentFrames, waveformMode: waveformModePreference, thumbnailsEnabled, keyframesEnabled, reducedMotion, ffmpegHwaccel } = allUserSettings.settings;
+ const { setCaptureFormat, setCustomOutDir, setKeyframeCut, setPlaybackVolume, setExportConfirmEnabled, setSimpleMode, setOutFormatLocked, setSafeOutputFileName, setKeyBindings, resetKeyBindings, setStoreProjectInWorkingDir, setCleanupChoices, darkMode, toggleDarkMode, setWaveformMode, setThumbnailsEnabled, setKeyframesEnabled, prefersReducedMotion, customOutDir } = allUserSettings;
const [showAdvancedSettings, setShowAdvancedSettings] = useState(!simpleMode);
diff --git a/src/renderer/src/components/Settings.tsx b/src/renderer/src/components/Settings.tsx
index 2c3e6ce5..a5422c62 100644
--- a/src/renderer/src/components/Settings.tsx
+++ b/src/renderer/src/components/Settings.tsx
@@ -75,7 +75,7 @@ function Settings({
}) {
const { t } = useTranslation();
- const { customOutDir, keyframeCut, toggleKeyframeCut, timecodeFormat, setTimecodeFormat, invertCutSegments, setInvertCutSegments, askBeforeClose, setAskBeforeClose, enableImportChapters, setEnableImportChapters, enableAskForFileOpenAction, setEnableAskForFileOpenAction, autoSaveProjectFile, setAutoSaveProjectFile, invertTimelineScroll, setInvertTimelineScroll, language, setLanguage, hideNotifications, setHideNotifications, hideOsNotifications, setHideOsNotifications, autoLoadTimecode, setAutoLoadTimecode, enableAutoHtml5ify, setEnableAutoHtml5ify, customFfPath, setCustomFfPath, storeProjectInWorkingDir, mouseWheelZoomModifierKey, setMouseWheelZoomModifierKey, mouseWheelFrameSeekModifierKey, setMouseWheelFrameSeekModifierKey, mouseWheelKeyframeSeekModifierKey, setMouseWheelKeyframeSeekModifierKey, segmentMouseModifierKey, setSegmentMouseModifierKey, captureFrameMethod, setCaptureFrameMethod, captureFrameQuality, setCaptureFrameQuality, captureFrameFileNameFormat, setCaptureFrameFileNameFormat, enableNativeHevc, setEnableNativeHevc, enableUpdateCheck, setEnableUpdateCheck, allowMultipleInstances, setAllowMultipleInstances, preferStrongColors, setPreferStrongColors, treatInputFileModifiedTimeAsStart, setTreatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, setTreatOutputFileModifiedTimeAsStart, exportConfirmEnabled, toggleExportConfirmEnabled, storeWindowBounds, setStoreWindowBounds, reducedMotion, setReducedMotion, ffmpegHwaccel, setFfmpegHwaccel } = useUserSettings();
+ const { customOutDir, keyframeCut, toggleKeyframeCut, timecodeFormat, setTimecodeFormat, invertCutSegments, setInvertCutSegments, askBeforeClose, setAskBeforeClose, enableImportChapters, setEnableImportChapters, enableAskForFileOpenAction, setEnableAskForFileOpenAction, autoSaveProjectFile, setAutoSaveProjectFile, invertTimelineScroll, setInvertTimelineScroll, language, setLanguage, hideNotifications, setHideNotifications, hideOsNotifications, setHideOsNotifications, autoLoadTimecode, setAutoLoadTimecode, enableAutoHtml5ify, setEnableAutoHtml5ify, customFfPath, setCustomFfPath, storeProjectInWorkingDir, mouseWheelZoomModifierKey, setMouseWheelZoomModifierKey, mouseWheelFrameSeekModifierKey, setMouseWheelFrameSeekModifierKey, mouseWheelKeyframeSeekModifierKey, setMouseWheelKeyframeSeekModifierKey, segmentMouseModifierKey, setSegmentMouseModifierKey, captureFrameMethod, setCaptureFrameMethod, captureFrameQuality, setCaptureFrameQuality, captureFrameFileNameFormat, setCaptureFrameFileNameFormat, enableNativeHevc, setEnableNativeHevc, enableUpdateCheck, setEnableUpdateCheck, allowMultipleInstances, setAllowMultipleInstances, preferStrongColors, setPreferStrongColors, theme, setTheme, treatInputFileModifiedTimeAsStart, setTreatInputFileModifiedTimeAsStart, treatOutputFileModifiedTimeAsStart, setTreatOutputFileModifiedTimeAsStart, exportConfirmEnabled, toggleExportConfirmEnabled, storeWindowBounds, setStoreWindowBounds, reducedMotion, setReducedMotion, ffmpegHwaccel, setFfmpegHwaccel } = useUserSettings();
const onLangChange = useCallback<ChangeEventHandler<HTMLSelectElement>>((e) => {
const { value } = e.target;
@@ -469,6 +469,17 @@ function Settings({
</Row>
)}
+ <Row>
+ <KeyCell>{t('Theme')}</KeyCell>
+ <td>
+ <Select value={theme} onChange={(e) => setTheme(e.target.value as Config['theme'])}>
+ {Object.entries({ system: t('System default'), dark: t('Dark'), light: t('Light') } satisfies Record<Config['theme'], string>).map(([key, value]) => (
+ <option key={key} value={key}>{value}</option>
+ ))}
+ </Select>
+ </td>
+ </Row>
+
<Row>
<KeyCell>{t('Prefer strong colors')}</KeyCell>
<td>
diff --git a/src/renderer/src/hooks/useUserSettingsRoot.ts b/src/renderer/src/hooks/useUserSettingsRoot.ts
index 4730ad4a..a768de3c 100644
--- a/src/renderer/src/hooks/useUserSettingsRoot.ts
+++ b/src/renderer/src/hooks/useUserSettingsRoot.ts
@@ -7,12 +7,14 @@ import type { Config } from '../../../common/types.js';
import { errorToast } from '../swal';
import isDev from '../isDev';
import { mySpring, emitter as animationsEmitter } from '../animations';
+import mainApi from '../mainApi';
const remote = window.require('@electron/remote');
const { systemPreferences } = remote;
const { configStore } = remote.require('./index.js');
const animationSettings = systemPreferences.getAnimationSettings();
+const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
export default function useUserSettingsRoot() {
const firstUpdateRef = useRef(true);
@@ -175,8 +177,8 @@ export default function useUserSettingsRoot() {
useEffect(() => safeSetConfig({ cleanupChoices }), [cleanupChoices]);
const [allowMultipleInstances, setAllowMultipleInstances] = useState(safeGetConfigInitial('allowMultipleInstances'));
useEffect(() => safeSetConfig({ allowMultipleInstances }), [allowMultipleInstances]);
- const [darkMode, setDarkMode] = useState(safeGetConfigInitial('darkMode'));
- useEffect(() => safeSetConfig({ darkMode }), [darkMode]);
+ const [theme, setTheme] = useState(safeGetConfigInitial('theme'));
+ useEffect(() => safeSetConfig({ theme }), [theme]);
const [preferStrongColors, setPreferStrongColors] = useState(safeGetConfigInitial('preferStrongColors'));
useEffect(() => safeSetConfig({ preferStrongColors }), [preferStrongColors]);
const [outputFileNameMinZeroPadding, setOutputFileNameMinZeroPadding] = useState(safeGetConfigInitial('outputFileNameMinZeroPadding'));
@@ -212,7 +214,21 @@ export default function useUserSettingsRoot() {
};
}, []);
- const toggleDarkMode = useCallback(() => setDarkMode((v) => !v), []);
+ // note: themeSource must be 'system' for prefers-color-scheme to report the OS theme
+ useEffect(() => {
+ mainApi.setThemeSource(theme);
+ }, [theme]);
+
+ const [systemDarkMode, setSystemDarkMode] = useState(darkModeMediaQuery.matches);
+ useEffect(() => {
+ const onChange = (e: MediaQueryListEvent) => setSystemDarkMode(e.matches);
+ darkModeMediaQuery.addEventListener('change', onChange);
+ return () => darkModeMediaQuery.removeEventListener('change', onChange);
+ }, []);
+
+ const darkMode = theme === 'system' ? systemDarkMode : theme === 'dark';
+
+ const toggleDarkMode = useCallback(() => setTheme(darkMode ? 'light' : 'dark'), [darkMode]);
const prefersReducedMotion = useMemo(() => {
if (reducedMotion !== 'user') return reducedMotion === 'always';
@@ -305,7 +321,7 @@ export default function useUserSettingsRoot() {
enableUpdateCheck,
cleanupChoices,
allowMultipleInstances,
- darkMode,
+ theme,
preferStrongColors,
outputFileNameMinZeroPadding,
cutFromAdjustmentFrames,
@@ -387,6 +403,8 @@ export default function useUserSettingsRoot() {
setEnableUpdateCheck,
setCleanupChoices,
setAllowMultipleInstances,
+ darkMode,
+ setTheme,
toggleDarkMode,
setPreferStrongColors,
setOutputFileNameMinZeroPadding,