- 替换 prompt() 为 InputDialog Vue 模态组件 - 替换 alert()/confirm() 为 Electron showMessageBox IPC - 添加 dialog:showMessage / dialog:showConfirm IPC 通道
33 lines
1.6 KiB
JavaScript
33 lines
1.6 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),
|
|
showMessage: (options) => ipcRenderer.invoke('dialog:showMessage', options),
|
|
showConfirm: (options) => ipcRenderer.invoke('dialog:showConfirm', 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)
|
|
}
|
|
}
|
|
})
|