1 回答
TA贡献1831条经验 获得超9个赞
所以我想出的解决方案如下:
在浏览器端/渲染器进程(在index.tsx)中,我执行以下操作:
// index.tsx (renderer process)
// ...
export const GLOBAL_SENDER_ID = uuidV4();
const store = storeCreator({
level: 'renderer',
reducer: renderersReducer,
sagas: mainAppWindowSagas,
senderId: GLOBAL_SENDER_ID,
});
const listenerRemover = listenToFromMainDispatchedActions(store, GLOBAL_SENDER_ID);
const cleanup = (): void => {
appLogger.log('WINDOW CLOSING');
listenerRemover();
window.removeEventListener('beforeunload', cleanup);
}
window.addEventListener('beforeunload', cleanup)
...
在主进程中,我删除了所有 ipcMain 对应项:
// index.ts
import { app, ipcMain } from 'electron';
import main from './main'
// ....
app.whenReady()
.then(main)
.catch((error) => {
appLogger.error(TAG, error);
});
// .....
app.on('before-quit', () => {
Object.values(IPCChannels).forEach(
(channel) => {
ipcMain.removeAllListeners(channel);
}
);
appLogger.log('CLEANED ALL IPCS');
appLogger.log('Done, BYEBYE');
});
它似乎按预期工作并且我设法在相关位置看到日志,虽然我不太确定这种方法的有效性,但我会在几天内不回答我的问题(今天是 13.08.2020 12:15CEST)。
如果我在一周左右的时间里得不到任何其他/更好的答案,我会接受我的答案作为正确答案。
添加回答
举报
