feat: implement secure IPC-based file export for Electron

Replace sandboxed Capacitor filesystem with native IPC for reliable file exports:
- Add IPC handler in main process for direct Downloads folder access
- Expose secure electronAPI via contextBridge in preload script
- Update ElectronPlatformService to use native IPC with web fallback
- Add TypeScript definitions for electron APIs
- Fix file export issues where files were trapped in virtual filesystem
- Enable proper date-stamped backup filenames in Downloads folder
- Follow Electron security best practices with process isolation

Files now export directly to ~/Downloads with exact path feedback.
This commit is contained in:
Matthew Raymer
2025-07-06 03:46:28 +00:00
parent 10562b7c47
commit e883029531
7 changed files with 328 additions and 159 deletions

33
src/types/global.d.ts vendored
View File

@@ -33,4 +33,37 @@ declare module '@jlongster/sql.js' {
}) => Promise<SQL>;
export default initSqlJs;
}
/**
* Electron API types for the main world context bridge.
*
* These types define the secure IPC APIs exposed by the preload script
* to the renderer process for native Electron functionality.
*/
interface ElectronAPI {
/**
* Export data to the user's Downloads folder.
*
* @param fileName - The name of the file to save (e.g., 'backup-2025-07-06.json')
* @param data - The content to write to the file (string)
* @returns Promise with success status, file path, or error message
*/
exportData: (fileName: string, data: string) => Promise<{
success: boolean;
path?: string;
error?: string;
}>;
}
/**
* Global window interface extension for Electron APIs.
*
* This makes the electronAPI available on the window object
* in TypeScript without type errors.
*/
declare global {
interface Window {
electronAPI: ElectronAPI;
}
}