gpt4 book ai didi

node.js - 如何从另一个ipcMain命令调用ipcMain命令?

转载 作者:行者123 更新时间:2023-12-03 12:28:16 25 4
gpt4 key购买 nike

不幸的是,我是 Electron 的新手,为了变干,我需要从loadFolders内部启动makeFolderloadFolders将触发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)
}
})
})

最佳答案

阅读 Electron 文档。另外,了解Node中的“事件发射器和监听器”。

在electronic中,您只有一个主进程(如服务器)和多个渲染器进程(如浏览器中的选项卡)。

IPC代表进程间通信。但是在主要过程中并不需要IPC。例如,您可以使用常规函数调用。

但是,如果您需要从主进程(或反之亦然)或在渲染器进程之间与渲染器进程“对话”,则分别使用ipcMain()和ipcRender()。

关于node.js - 如何从另一个ipcMain命令调用ipcMain命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58760613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com