mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-26 13:45:16 -07:00
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:
@@ -2,40 +2,25 @@ import type { PlatformFilesystem, FileFilter } from '@/platform/types';
|
|||||||
|
|
||||||
export const tauriFilesystem: PlatformFilesystem = {
|
export const tauriFilesystem: PlatformFilesystem = {
|
||||||
async saveFile(filename: string, blob: Blob, filters?: FileFilter[]) {
|
async saveFile(filename: string, blob: Blob, filters?: FileFilter[]) {
|
||||||
try {
|
const { save } = await import('@tauri-apps/plugin-dialog');
|
||||||
const { save } = await import('@tauri-apps/plugin-dialog');
|
const { writeFile } = await import('@tauri-apps/plugin-fs');
|
||||||
const filePath = await save({
|
|
||||||
defaultPath: filename,
|
|
||||||
filters: filters || [],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (filePath) {
|
const filePath = await save({
|
||||||
let resolvedPath = '';
|
defaultPath: filename,
|
||||||
if (typeof filePath === 'string') {
|
filters: filters || [],
|
||||||
resolvedPath = filePath;
|
});
|
||||||
} else if (filePath && typeof filePath === 'object' && 'path' in filePath) {
|
|
||||||
resolvedPath = (filePath as { path: string }).path;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!resolvedPath) {
|
if (!filePath) return; // User cancelled the dialog
|
||||||
throw new Error('Failed to resolve save path');
|
|
||||||
}
|
|
||||||
|
|
||||||
const { writeFile } = await import('@tauri-apps/plugin-fs');
|
const resolvedPath = typeof filePath === 'string'
|
||||||
const arrayBuffer = await blob.arrayBuffer();
|
? filePath
|
||||||
await writeFile(resolvedPath, new Uint8Array(arrayBuffer));
|
: (filePath as { path: string }).path;
|
||||||
}
|
|
||||||
} catch (error) {
|
if (!resolvedPath) {
|
||||||
console.error('Failed to use Tauri dialog, falling back to browser download:', error);
|
throw new Error('Failed to resolve save path from dialog');
|
||||||
// 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 arrayBuffer = await blob.arrayBuffer();
|
||||||
|
await writeFile(resolvedPath, new Uint8Array(arrayBuffer));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user