openpencil/electron/preload.ts
Kayshen-X d51510d7e9 feat(electron): integrate Electron framework for desktop application support
- Add Electron configuration and main process setup for building a desktop application.
- Implement IPC communication for file operations (open, save) between the renderer and main processes.
- Create a preload script to expose Electron APIs to the renderer.
- Update package.json to include Electron and related dependencies.
- Enhance the build process with electron-builder for packaging the application.
- Introduce a new electron-builder.yml configuration file for build settings.
- Modify Vite configuration to support Electron-specific builds.
- Update UI components to accommodate Electron's window management and drag regions.
2026-02-20 20:19:06 +08:00

25 lines
747 B
TypeScript

import { contextBridge, ipcRenderer } from 'electron'
export interface ElectronAPI {
isElectron: true
openFile: () => Promise<{ filePath: string; content: string } | null>
saveFile: (
content: string,
defaultPath?: string,
) => Promise<string | null>
saveToPath: (filePath: string, content: string) => Promise<string>
}
const api: ElectronAPI = {
isElectron: true,
openFile: () => ipcRenderer.invoke('dialog:openFile'),
saveFile: (content: string, defaultPath?: string) =>
ipcRenderer.invoke('dialog:saveFile', { content, defaultPath }),
saveToPath: (filePath: string, content: string) =>
ipcRenderer.invoke('dialog:saveToPath', { filePath, content }),
}
contextBridge.exposeInMainWorld('electronAPI', api)