i think i got step one working
This commit is contained in:
71
frontend/src/lib/tauri-bridge.ts
Normal file
71
frontend/src/lib/tauri-bridge.ts
Normal file
@ -0,0 +1,71 @@
|
||||
/**
|
||||
* tauri-bridge.ts
|
||||
*
|
||||
* Polyfills window.electronAPI with Tauri equivalents so all existing
|
||||
* call-sites in App.tsx, hooks, and stores continue to work unchanged.
|
||||
*
|
||||
* Imported once at the top of main.tsx.
|
||||
*/
|
||||
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open, save } from '@tauri-apps/plugin-dialog';
|
||||
import { readTextFile, writeTextFile } from '@tauri-apps/plugin-fs';
|
||||
|
||||
const VIDEO_FILTERS = [
|
||||
{ name: 'Video Files', extensions: ['mp4', 'avi', 'mov', 'mkv', 'webm'] },
|
||||
{ name: 'Audio Files', extensions: ['m4a', 'wav', 'mp3', 'flac'] },
|
||||
{ name: 'All Files', extensions: ['*'] },
|
||||
];
|
||||
|
||||
const PROJECT_FILTERS = [
|
||||
{ name: 'TalkEdit Project', extensions: ['aive'] },
|
||||
];
|
||||
|
||||
const EXPORT_FILTERS = [
|
||||
{ name: 'Video Files', extensions: ['mp4', 'mov', 'webm'] },
|
||||
{ name: 'Project Files', extensions: ['aive'] },
|
||||
];
|
||||
|
||||
window.electronAPI = {
|
||||
openFile: async (_options?: Record<string, unknown>): Promise<string | null> => {
|
||||
const result = await open({
|
||||
multiple: false,
|
||||
filters: VIDEO_FILTERS,
|
||||
});
|
||||
return typeof result === 'string' ? result : null;
|
||||
},
|
||||
|
||||
saveFile: async (_options?: Record<string, unknown>): Promise<string | null> => {
|
||||
const result = await save({ filters: EXPORT_FILTERS });
|
||||
return result ?? null;
|
||||
},
|
||||
|
||||
openProject: async (): Promise<string | null> => {
|
||||
const result = await open({
|
||||
multiple: false,
|
||||
filters: PROJECT_FILTERS,
|
||||
});
|
||||
return typeof result === 'string' ? result : null;
|
||||
},
|
||||
|
||||
getBackendUrl: (): Promise<string> => {
|
||||
return invoke<string>('get_backend_url');
|
||||
},
|
||||
|
||||
encryptString: (data: string): Promise<string> => {
|
||||
return invoke<string>('encrypt_string', { data });
|
||||
},
|
||||
|
||||
decryptString: (encrypted: string): Promise<string> => {
|
||||
return invoke<string>('decrypt_string', { encrypted });
|
||||
},
|
||||
|
||||
readFile: (path: string): Promise<string> => {
|
||||
return readTextFile(path);
|
||||
},
|
||||
|
||||
writeFile: async (path: string, content: string): Promise<boolean> => {
|
||||
await writeTextFile(path, content);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
@ -1,5 +1,7 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
// Must be imported before App so window.electronAPI is patched before any component runs.
|
||||
import './lib/tauri-bridge';
|
||||
import App from './App';
|
||||
import './index.css';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user