mirror of
https://github.com/ZSeven-W/openpencil.git
synced 2026-06-01 03:14:29 +07:00
- 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.
25 lines
747 B
TypeScript
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)
|