不幸的是,我是电子的新手,要努力变干,我需要从loadFolders
内部开始makeFolder
,loadFolders
将触发ipcRenderer加载我更新的文件夹的事件名称
显示了所有在线示例,这些示例将消息从ipcMain发送到ipcRenderer,但从未从一个后端函数发送到另一个后端函数,这有可能吗?
ipcMain.on('loadFolders', (e, args) => {
// ...
// does some stuff to read folder names from the file system
// ...
// sends folder list to the view
mainWindow.webContents.send('folderItems', items)
})
ipcMain.on('makeFolder', (e, args) => {
return new Promise((resolve, reject) => {
try {
// ...
// creates a folder from args
// ** need to call the loadFolders method here in order to read
// updated list from the filesystem **
} catch (err) {
reject(err)
}
})
})
答案 0 :(得分:0)
阅读电子文档。另外,了解Node中的“事件发射器和侦听器”。
在电子中,您只有一个主进程(如服务器)和多个渲染器进程(如浏览器中的选项卡)。
IPC代表进程间通信。但是在主要过程中不需要IPC。例如,您可以使用常规函数调用。
但是,如果您需要从主进程“反之”或在渲染器进程之间“与”渲染器进程“交谈”,则分别使用ipcMain()和ipcRender()。