- Electron 主进程:窗口管理、IPC、项目读写、打包引擎 - Vue 3 前端:4 个视图页面、3 个组件、Pinia 状态管理 - 生成应用模板:Express 后端 + Electron 窗口 - 支持资源导入、应用配置、跨平台打包
31 lines
1.4 KiB
JavaScript
31 lines
1.4 KiB
JavaScript
const { contextBridge, ipcRenderer } = require('electron')
|
|
|
|
contextBridge.exposeInMainWorld('api', {
|
|
dialog: {
|
|
selectDirectory: () => ipcRenderer.invoke('dialog:selectDirectory'),
|
|
selectFile: (options) => ipcRenderer.invoke('dialog:selectFile', options),
|
|
selectIcon: () => ipcRenderer.invoke('dialog:selectIcon'),
|
|
saveFile: (options) => ipcRenderer.invoke('dialog:saveFile', options)
|
|
},
|
|
dir: {
|
|
readTree: (dirPath) => ipcRenderer.invoke('dir:readTree', dirPath)
|
|
},
|
|
project: {
|
|
create: (name, dir) => ipcRenderer.invoke('project:create', name, dir),
|
|
load: (projectPath) => ipcRenderer.invoke('project:load', projectPath),
|
|
save: (projectPath, data) => ipcRenderer.invoke('project:save', projectPath, data),
|
|
importFiles: (projectPath, files) => ipcRenderer.invoke('project:importFiles', projectPath, files),
|
|
removeFile: (projectPath, relativePath) => ipcRenderer.invoke('project:removeFile', projectPath, relativePath),
|
|
setIcon: (projectPath, iconPath) => ipcRenderer.invoke('project:setIcon', projectPath, iconPath)
|
|
},
|
|
pack: {
|
|
start: (projectPath, outputPath) => ipcRenderer.invoke('pack:start', projectPath, outputPath),
|
|
cancel: () => ipcRenderer.invoke('pack:cancel'),
|
|
onProgress: (callback) => {
|
|
const handler = (_event, progress) => callback(progress)
|
|
ipcRenderer.on('pack:progress', handler)
|
|
return () => ipcRenderer.removeListener('pack:progress', handler)
|
|
}
|
|
}
|
|
})
|