Skip to content

The swiss army knife of lossless video/audio editing

Remember the last folder of open dialogs

Claudef8eac7442b02
diff --git a/src/common/types.ts b/src/common/types.ts
index c2921984..2356edcf 100644
--- a/src/common/types.ts
+++ b/src/common/types.ts
@@ -100,6 +100,7 @@ export const configSchema = z.object({
enableAutoHtml5ify: z.boolean(),
keyBindings: keyBindingSchema.array(),
customFfPath: z.string().or(z.undefined()),
+ lastDialogDir: z.string().or(z.undefined()),
storeProjectInWorkingDir: z.boolean(),
enableOverwriteOutput: z.boolean(),
mouseWheelZoomModifierKey: modifierKeySchema,
diff --git a/src/main/configStore.ts b/src/main/configStore.ts
index 15d5e492..8b1c5646 100644
--- a/src/main/configStore.ts
+++ b/src/main/configStore.ts
@@ -145,6 +145,7 @@ const defaults: Config = {
enableAutoHtml5ify: true,
keyBindings: defaultKeyBindings,
customFfPath: undefined,
+ lastDialogDir: undefined,
storeProjectInWorkingDir: true,
enableOverwriteOutput: true,
mouseWheelZoomModifierKey: 'ctrl',
diff --git a/src/renderer/src/dialogs/index.tsx b/src/renderer/src/dialogs/index.tsx
index a77ed871..4aca0978 100644
--- a/src/renderer/src/dialogs/index.tsx
+++ b/src/renderer/src/dialogs/index.tsx
@@ -7,6 +7,7 @@ import ky from 'ky';
import pMap from 'p-map';
import { formatDuration } from '../util/duration';
+import { dirname } from '../util/path';
import { parseRatio } from '../../../common/util';
import { parseYouTube } from '../edlFormats';
import { appPath, isMasBuild, isStoreBuild, isWindows, isWindowsStoreBuild, testFailFsOperation, trashFile, unlinkWithRetry } from '../util';
@@ -18,17 +19,32 @@ import isDev from '../isDev';
import mainApi from '../mainApi';
const { lstat } = window.require('node:fs/promises');
-const { dialog } = window.require('@electron/remote');
+const remote = window.require('@electron/remote');
+const { dialog } = remote;
+const { configStore } = remote.require('./index.js');
+// Without a defaultPath, Electron (since v43) opens dialogs in Downloads, and the OS no longer remembers the last used folder, so we remember it ourselves
+async function getLastDialogDir() {
+ const dir = configStore.get('lastDialogDir');
+ // A missing folder would end up in the file name box on Windows
+ if (dir == null || !(await lstat(dir).then((stat) => stat.isDirectory(), () => false))) return undefined;
+ return dir;
+}
+
// https://github.com/mifi/lossless-cut/issues/1495
export const showOpenDialog = async ({
filters = isWindows ? [{ name: i18n.t('All Files'), extensions: ['*'] }] : undefined,
title,
+ defaultPath,
...props
-}: Omit<Parameters<typeof dialog.showOpenDialog>[0], 'title'> & { title: string }) => (
- dialog.showOpenDialog({ ...props, title, ...(filters != null ? { filters } : {}) })
-);
+}: Omit<Parameters<typeof dialog.showOpenDialog>[0], 'title'> & { title: string }) => {
+ const effectiveDefaultPath = defaultPath || await getLastDialogDir();
+ const result = await dialog.showOpenDialog({ ...props, title, ...(effectiveDefaultPath != null && { defaultPath: effectiveDefaultPath }), ...(filters != null ? { filters } : {}) });
+ const [firstPath] = result.filePaths;
+ if (!result.canceled && firstPath != null) configStore.set('lastDialogDir', dirname(firstPath));
+ return result;
+};
export async function askForYouTubeInput({ fileDuration }: { fileDuration?: number | undefined }) {
const example = i18n.t('YouTube video description\n00:00 Intro\n00:01 Chapter 2\n00:00:02.123 Chapter 3');