fix(xod-client-electron): do not send data through IPC to the renderer if it was destroyed

This commit is contained in:
Kirill Shumilov
2018-10-19 17:06:53 +03:00
parent 54ac82d164
commit fd7e362cbf

View File

@@ -6,7 +6,17 @@ import { errorToPlainObject } from './utils';
export default (fn, eventName) => {
const STATES = getAllStatesForEvent(eventName);
ipcMain.on(STATES.BEGIN, (event, payload) => {
const onProgress = data => event.sender.send(STATES.PROCESS, data);
// Prevent sending data to the closed window
// because it produces an exception
if (event.sender.isDestroyed()) return;
const onProgress = data => {
// Prevent sending data to the closed window
// because it produces an exception
if (event.sender.isDestroyed()) return;
event.sender.send(STATES.PROCESS, data);
};
fn(event, payload, onProgress)
.then(res => event.sender.send(STATES.COMPLETE, res))