fix: remove silent browser fallback that bypasses save dialog path

Amp-Thread-ID: https://ampcode.com/threads/T-019c7c3e-072f-7109-86a7-072a6b309891
Co-authored-by: Amp <[email protected]>
This commit is contained in:
lemassykoi
2026-02-20 19:27:41 +01:00
co-authored by Amp
parent d4794f78e1
commit 31ea3c68a5
+16 -31
View File
@@ -2,40 +2,25 @@ import type { PlatformFilesystem, FileFilter } from '@/platform/types';
export const tauriFilesystem: PlatformFilesystem = {
async saveFile(filename: string, blob: Blob, filters?: FileFilter[]) {
try {
const { save } = await import('@tauri-apps/plugin-dialog');
const filePath = await save({
defaultPath: filename,
filters: filters || [],
});
const { save } = await import('@tauri-apps/plugin-dialog');
const { writeFile } = await import('@tauri-apps/plugin-fs');
if (filePath) {
let resolvedPath = '';
if (typeof filePath === 'string') {
resolvedPath = filePath;
} else if (filePath && typeof filePath === 'object' && 'path' in filePath) {
resolvedPath = (filePath as { path: string }).path;
}
const filePath = await save({
defaultPath: filename,
filters: filters || [],
});
if (!resolvedPath) {
throw new Error('Failed to resolve save path');
}
if (!filePath) return; // User cancelled the dialog
const { writeFile } = await import('@tauri-apps/plugin-fs');
const arrayBuffer = await blob.arrayBuffer();
await writeFile(resolvedPath, new Uint8Array(arrayBuffer));
}
} catch (error) {
console.error('Failed to use Tauri dialog, falling back to browser download:', error);
// Fall back to browser download if Tauri dialog fails
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
window.URL.revokeObjectURL(url);
document.body.removeChild(a);
const resolvedPath = typeof filePath === 'string'
? filePath
: (filePath as { path: string }).path;
if (!resolvedPath) {
throw new Error('Failed to resolve save path from dialog');
}
const arrayBuffer = await blob.arrayBuffer();
await writeFile(resolvedPath, new Uint8Array(arrayBuffer));
},
};