mirror of
https://github.com/jamiepine/voicebox.git
synced 2026-09-16 13:20:39 -07:00
- Replaced direct Tauri API calls with a unified platform context across multiple components, enhancing code maintainability and readability. - Removed the deprecated tauri.ts file, consolidating platform-related logic into the new PlatformContext. - Updated components such as App, AudioPlayer, and ServerSettings to utilize the new platform context for lifecycle management and server interactions. - Improved platform detection and handling for audio playback and system audio capture functionalities. - Ensured consistent error handling and user feedback across the application when interacting with platform-specific features.
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
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 || [],
|
|
});
|
|
|
|
if (filePath) {
|
|
const { writeBinaryFile } = await import('@tauri-apps/plugin-fs');
|
|
const arrayBuffer = await blob.arrayBuffer();
|
|
await writeBinaryFile(filePath, 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);
|
|
}
|
|
},
|
|
};
|