| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- import { contextBridge, ipcRenderer } from 'electron';
- // ─── Types ───────────────────────────────────────────────────────────────────
- interface AppConfig {
- recentProjects: RecentProject[];
- lastActiveProjectPath?: string;
- }
- interface RecentProject {
- name: string;
- path: string;
- lastOpenedAt: string;
- novelType: string;
- }
- interface ElectronAPI {
- /**
- * Opens the native OS folder selection dialog.
- * Returns the selected folder path, or null if the user cancelled.
- */
- selectFolder: () => Promise<string | null>;
- /**
- * Reads the global app config from the Electron userData directory.
- */
- getAppConfig: () => Promise<AppConfig>;
- /**
- * Writes the global app config to the Electron userData directory.
- */
- saveAppConfig: (config: AppConfig) => Promise<{ success: boolean }>;
- }
- // ─── Expose API via contextBridge ─────────────────────────────────────────────
- const electronAPI: ElectronAPI = {
- selectFolder: () => ipcRenderer.invoke('select-folder'),
- getAppConfig: () => ipcRenderer.invoke('get-app-config'),
- saveAppConfig: (config: AppConfig) => ipcRenderer.invoke('save-app-config', config),
- };
- contextBridge.exposeInMainWorld('electronAPI', electronAPI);
|