Files
Toju/electron/preload.ts

48 lines
1.7 KiB
TypeScript

import { contextBridge, ipcRenderer } from 'electron';
import { Command, Query } from './cqrs/types';
export interface ElectronAPI {
// Window controls
minimizeWindow: () => void;
maximizeWindow: () => void;
closeWindow: () => void;
// System utilities
openExternal: (url: string) => Promise<boolean>;
getSources: () => Promise<{ id: string; name: string; thumbnail: string }[]>;
getAppDataPath: () => Promise<string>;
readFile: (filePath: string) => Promise<string>;
writeFile: (filePath: string, data: string) => Promise<boolean>;
fileExists: (filePath: string) => Promise<boolean>;
ensureDir: (dirPath: string) => Promise<boolean>;
// CQRS database operations
command: <T = unknown>(command: Command) => Promise<T>;
query: <T = unknown>(query: Query) => Promise<T>;
}
const electronAPI: ElectronAPI = {
minimizeWindow: () => ipcRenderer.send('window-minimize'),
maximizeWindow: () => ipcRenderer.send('window-maximize'),
closeWindow: () => ipcRenderer.send('window-close'),
openExternal: (url) => ipcRenderer.invoke('open-external', url),
getSources: () => ipcRenderer.invoke('get-sources'),
getAppDataPath: () => ipcRenderer.invoke('get-app-data-path'),
readFile: (filePath) => ipcRenderer.invoke('read-file', filePath),
writeFile: (filePath, data) => ipcRenderer.invoke('write-file', filePath, data),
fileExists: (filePath) => ipcRenderer.invoke('file-exists', filePath),
ensureDir: (dirPath) => ipcRenderer.invoke('ensure-dir', dirPath),
command: (command) => ipcRenderer.invoke('cqrs:command', command),
query: (query) => ipcRenderer.invoke('cqrs:query', query)
};
contextBridge.exposeInMainWorld('electronAPI', electronAPI);
declare global {
interface Window {
electronAPI: ElectronAPI;
}
}