fix: restore background toggle and parent save dialog

This commit is contained in:
webadderall
2026-03-18 14:26:42 +11:00
parent 5e88dcf995
commit 843b6895e4
5 changed files with 48 additions and 8 deletions
+10 -5
View File
@@ -1,4 +1,5 @@
import { ipcMain, desktopCapturer, BrowserWindow, shell, app, dialog, systemPreferences } from 'electron'
import type { SaveDialogOptions } from 'electron'
import { execFile, spawn, spawnSync } from 'node:child_process'
import type { ChildProcessWithoutNullStreams } from 'node:child_process'
@@ -2592,20 +2593,24 @@ export function registerIpcHandlers(
}
})
ipcMain.handle('save-exported-video', async (_, videoData: ArrayBuffer, fileName: string) => {
ipcMain.handle('save-exported-video', async (event, videoData: ArrayBuffer, fileName: string) => {
try {
// Determine file type from extension
const isGif = fileName.toLowerCase().endsWith('.gif');
const filters = isGif
? [{ name: 'GIF Image', extensions: ['gif'] }]
: [{ name: 'MP4 Video', extensions: ['mp4'] }];
const result = await dialog.showSaveDialog({
const parentWindow = BrowserWindow.fromWebContents(event.sender)
const saveDialogOptions: SaveDialogOptions = {
title: isGif ? 'Save Exported GIF' : 'Save Exported Video',
defaultPath: path.join(app.getPath('downloads'), fileName),
filters,
properties: ['createDirectory', 'showOverwriteConfirmation']
});
properties: ['createDirectory', 'showOverwriteConfirmation'],
}
const result = parentWindow
? await dialog.showSaveDialog(parentWindow, saveDialogOptions)
: await dialog.showSaveDialog(saveDialogOptions)
if (result.canceled || !result.filePath) {
return {
@@ -231,6 +231,7 @@ export function SettingsPanel({
cropRegion,
onCropChange,
aspectRatio,
onAspectRatioChange,
videoElement,
exportQuality = "good",
onExportQualityChange,
@@ -265,6 +266,10 @@ export function SettingsPanel({
const [customImages, setCustomImages] = useState<string[]>(
initialEditorPreferences.customWallpapers,
);
const removeBackgroundStateRef = useRef<{
aspectRatio: AspectRatio;
padding: number;
} | null>(null);
const fileInputRef = useRef<HTMLInputElement>(null);
useEffect(() => {
@@ -310,6 +315,7 @@ export function SettingsPanel({
const [gradient, setGradient] = useState<string>(
GRADIENTS.includes(selected) ? selected : GRADIENTS[0],
);
const removeBackgroundEnabled = aspectRatio === "native" && padding === 0;
const [backgroundTab, setBackgroundTab] = useState<BackgroundTab>(() =>
getBackgroundTabForWallpaper(selected),
);
@@ -336,6 +342,24 @@ export function SettingsPanel({
saveEditorPreferences({ customWallpapers: customImages });
}, [customImages]);
const handleRemoveBackgroundToggle = (checked: boolean) => {
if (checked) {
removeBackgroundStateRef.current = {
aspectRatio,
padding,
};
onAspectRatioChange?.("native");
onPaddingChange?.(0);
return;
}
if (removeBackgroundStateRef.current) {
onAspectRatioChange?.(removeBackgroundStateRef.current.aspectRatio);
onPaddingChange?.(removeBackgroundStateRef.current.padding);
removeBackgroundStateRef.current = null;
}
};
const webcamFileName = webcam?.sourcePath?.split(/[\\/]/).pop() ?? null;
const zoomEnabled = Boolean(selectedZoomDepth);
@@ -860,6 +884,14 @@ export function SettingsPanel({
parseInput={(t) => parseFloat(t.replace(/%$/, ""))}
/>
</div>
<div className="col-span-2 flex items-center justify-between p-2 rounded-lg bg-white/5 border border-white/5">
<div className="text-[10px] font-medium text-slate-300">{tSettings("effects.removeBackground")}</div>
<Switch
checked={removeBackgroundEnabled}
onCheckedChange={handleRemoveBackgroundToggle}
className="data-[state=checked]:bg-[#2563EB] scale-90"
/>
</div>
</div>
<Button
+2 -1
View File
@@ -39,7 +39,8 @@
"webcamShadow": "Webcam Shadow",
"shadow": "Shadow",
"roundness": "Roundness",
"padding": "Padding"
"padding": "Padding",
"removeBackground": "Remove background"
},
"crop": {
"title": "Crop Video",
+2 -1
View File
@@ -39,7 +39,8 @@
"webcamShadow": "Sombra de cámara",
"shadow": "Sombra",
"roundness": "Redondez",
"padding": "Relleno"
"padding": "Relleno",
"removeBackground": "Quitar fondo"
},
"crop": {
"title": "Recortar video",
+2 -1
View File
@@ -39,7 +39,8 @@
"webcamShadow": "摄像头阴影",
"shadow": "阴影",
"roundness": "圆角",
"padding": "内边距"
"padding": "内边距",
"removeBackground": "移除背景"
},
"crop": {
"title": "裁剪视频",