我目前有一个文件(mainHandler.ts),里面有如下内容:
export const registerIpcMainHandlers = () => {
ipcMain.on('message1' , (event, data) => {
console.log(`Message received from ${event.sender.id}: ${data}`);
event.sender.send('response', 'Response message from main process.');
});
ipcMain.on('message2' , (event, data) => {
console.log(`Message received from ${event.sender.id}: ${data}`);
event.sender.send('response', 'Response message from main process.');
});
...
}
现在我想要拆分里面的一些监听方法到其他文件去(例如:subHandlers/handler1.ts):
mainHandler.ts
subHandlers/
handler1.ts
应该怎么做呢?应该如何把subHandlers/handler1.ts
中的on方法们引入到:registerIpcMainHandlers里面去呢?