Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Use addEventListener #2723

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,28 @@ const operationCountLimit = parseInt(query.operationCountLimit, 10);
const averageTracker = new AverageTracker({limit: operationCountLimit});
const childPidsById = new Map();

const cleanUp = () => {
managerWebContents.removeListener('crashed', destroyRenderer);
managerWebContents.removeListener('destroyed', destroyRenderer);
window.removeEventListener('beforeunload', cleanUp)
};

const destroyRenderer = () => {
if (!managerWebContents.isDestroyed()) {
managerWebContents.removeListener('crashed', destroyRenderer);
managerWebContents.removeListener('destroyed', destroyRenderer);
cleanUp()
}
const win = remote.BrowserWindow.fromWebContents(remote.getCurrentWebContents());
if (win && !win.isDestroyed()) {
win.destroy();
}
};

const managerWebContentsId = parseInt(query.managerWebContentsId, 10);
const managerWebContents = remote.webContents.fromId(managerWebContentsId);
if (managerWebContents && !managerWebContents.isDestroyed()) {
managerWebContents.on('crashed', destroyRenderer);
managerWebContents.on('destroyed', destroyRenderer);
window.onbeforeunload = () => {
managerWebContents.removeListener('crashed', destroyRenderer);
managerWebContents.removeListener('destroyed', destroyRenderer);
};
window.addEventListener('beforeunload', cleanup);
}

const channelName = query.channelName;
Expand Down