Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
feat: implement handlers to store last export location
AbhinRustagic40727672ffa
diff --git a/electron/ipc/handlers.ts b/electron/ipc/handlers.tsindex 95ed797e7..9a8e9cafe 100644--- a/electron/ipc/handlers.ts+++ b/electron/ipc/handlers.ts@@ -822,54 +822,72 @@ export function registerIpcHandlers(* @returns Object with success status, optional file path, and error details.*/- ipcMain.handle("save-exported-video", async (_, videoData: ArrayBuffer, fileName: string) => {- try {- // Determine file type from extension- const isGif = fileName.toLowerCase().endsWith(".gif");- const filters = isGif- ? [{ name: mainT("dialogs", "fileDialogs.gifImage"), extensions: ["gif"] }]- : [{ name: mainT("dialogs", "fileDialogs.mp4Video"), extensions: ["mp4"] }];-- const result = await dialog.showSaveDialog({- title: isGif- ? mainT("dialogs", "fileDialogs.saveGif")- : mainT("dialogs", "fileDialogs.saveVideo"),- defaultPath: path.join(app.getPath("downloads"), fileName),- filters,- properties: ["createDirectory", "showOverwriteConfirmation"],- });+ ipcMain.handle(+ "save-exported-video",+ async (_, videoData: ArrayBuffer, fileName: string, exportFolder?: string) => {+ try {+ // Determine file type from extension+ const isGif = fileName.toLowerCase().endsWith(".gif");+ const filters = isGif+ ? [{ name: mainT("dialogs", "fileDialogs.gifImage"), extensions: ["gif"] }]+ : [{ name: mainT("dialogs", "fileDialogs.mp4Video"), extensions: ["mp4"] }];++ // Prefer the user's last export folder if it still exists, otherwise fall+ // back to ~/Downloads. Validation must happen here because the renderer+ // can't stat the filesystem.+ let defaultDir = app.getPath("downloads");+ if (exportFolder) {+ try {+ const stats = await fs.stat(exportFolder);+ if (stats.isDirectory()) {+ defaultDir = exportFolder;+ }+ } catch {+ // Folder was moved or deleted since the last export; keep Downloads.+ }+ }- if (result.canceled || !result.filePath) {- return {- success: false,- canceled: true,- message: "Export canceled",- };- }+ const result = await dialog.showSaveDialog({+ title: isGif+ ? mainT("dialogs", "fileDialogs.saveGif")+ : mainT("dialogs", "fileDialogs.saveVideo"),+ defaultPath: path.join(defaultDir, fileName),+ filters,+ properties: ["createDirectory", "showOverwriteConfirmation"],+ });- // --- FIX: Normalize the path for Windows compatibility ---- const normalizedPath = path.normalize(result.filePath);+ if (result.canceled || !result.filePath) {+ return {+ success: false,+ canceled: true,+ message: "Export canceled",+ };+ }- // Ensure the parent directory exists (Windows may fail if the folder is missing)- await fs.mkdir(path.dirname(normalizedPath), { recursive: true });- // --- END FIX ---+ // --- FIX: Normalize the path for Windows compatibility ---+ const normalizedPath = path.normalize(result.filePath);- await fs.writeFile(normalizedPath, Buffer.from(videoData));+ // Ensure the parent directory exists (Windows may fail if the folder is missing)+ await fs.mkdir(path.dirname(normalizedPath), { recursive: true });+ // --- END FIX ---- return {- success: true,- path: normalizedPath,- message: "Video exported successfully",- };- } catch (error) {- console.error("Failed to save exported video:", error);- return {- success: false,- message: "Failed to save exported video",- error: String(error),- };- }- });+ await fs.writeFile(normalizedPath, Buffer.from(videoData));++ return {+ success: true,+ path: normalizedPath,+ message: "Video exported successfully",+ };+ } catch (error) {+ console.error("Failed to save exported video:", error);+ return {+ success: false,+ message: "Failed to save exported video",+ error: String(error),+ };+ }+ },+ );ipcMain.handle("open-video-file-picker", async () => {try {const result = await dialog.showOpenDialog({diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex 7adc558e8..cf174fa28 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -31,7 +31,7 @@ import {import { computeFrameStepTime } from "@/lib/frameStep";import type { ProjectMedia } from "@/lib/recordingSession";import { matchesShortcut } from "@/lib/shortcuts";-import { loadUserPreferences, saveUserPreferences } from "@/lib/userPreferences";+import { loadUserPreferences, parentDirectoryOf, saveUserPreferences } from "@/lib/userPreferences";import { BackgroundLoadError } from "@/lib/wallpaper";import {getAspectRatioValue,@@ -1285,6 +1285,10 @@ export default function VideoEditor() {const handleExportSaved = useCallback((formatLabel: "GIF" | "Video", filePath: string) => {setExportedFilePath(filePath);+ const folder = parentDirectoryOf(filePath);+ if (folder) {+ saveUserPreferences({ exportFolder: folder });+ }toast.success(t("export.exportedSuccessfully", {format: formatLabel,@@ -1309,6 +1313,7 @@ export default function VideoEditor() {const saveResult = await window.electronAPI.saveExportedVideo(unsavedExport.arrayBuffer,unsavedExport.fileName,+ loadUserPreferences().exportFolder ?? undefined,);if (saveResult.canceled) {toast.info("Export canceled");@@ -1410,7 +1415,11 @@ export default function VideoEditor() {}}- const saveResult = await window.electronAPI.saveExportedVideo(arrayBuffer, fileName);+ const saveResult = await window.electronAPI.saveExportedVideo(+ arrayBuffer,+ fileName,+ loadUserPreferences().exportFolder ?? undefined,+ );if (saveResult.canceled) {setUnsavedExport({ arrayBuffer, fileName, format: "gif" });@@ -1550,7 +1559,11 @@ export default function VideoEditor() {}}- const saveResult = await window.electronAPI.saveExportedVideo(arrayBuffer, fileName);+ const saveResult = await window.electronAPI.saveExportedVideo(+ arrayBuffer,+ fileName,+ loadUserPreferences().exportFolder ?? undefined,+ );if (saveResult.canceled) {setUnsavedExport({ arrayBuffer, fileName, format: "mp4" });diff --git a/src/lib/userPreferences.ts b/src/lib/userPreferences.tsindex e0607880f..6947da5ef 100644--- a/src/lib/userPreferences.ts+++ b/src/lib/userPreferences.ts@@ -23,6 +23,8 @@ export interface UserPreferences {exportQuality: ExportQuality;/** Default export format */exportFormat: ExportFormat;+ /** Folder used for the most recent successful export, if any */+ exportFolder: string | null;}const DEFAULT_PREFS: UserPreferences = {@@ -30,6 +32,7 @@ const DEFAULT_PREFS: UserPreferences = {aspectRatio: "16:9",exportQuality: "good",exportFormat: "mp4",+ exportFolder: null,};function safeJsonParse(text: string | null): Record<string, unknown> | null {@@ -76,9 +79,24 @@ export function loadUserPreferences(): UserPreferences {raw.exportFormat === "gif" || raw.exportFormat === "mp4"? (raw.exportFormat as ExportFormat): DEFAULT_PREFS.exportFormat,+ exportFolder:+ typeof raw.exportFolder === "string" && raw.exportFolder.length > 0+ ? raw.exportFolder+ : DEFAULT_PREFS.exportFolder,};}+/**+ * Extracts the parent directory from a saved file path. Handles both POSIX+ * and Windows separators since the path comes from the OS save dialog.+ * Returns null if no separator is found.+ */+export function parentDirectoryOf(filePath: string): string | null {+ const lastSep = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));+ if (lastSep <= 0) return null;+ return filePath.slice(0, lastSep);+}+/*** Persist user preferences to localStorage.* Only the explicitly provided fields are updated.