This repository was archived by the owner on Jul 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 55
Clean up Electron win listeners on app reloadΒ #17
Copy link
Copy link
Open
Description
Using events in renderer process throw error on development console
saying Attempting to call a function in a renderer window that has been closed or released.
win.on('maximize', toggleMaxRestoreButtons);
win.on('unmaximize', toggleMaxRestoreButtons);
This will cause error because you haven't cleaned up correctly and a listener exists on a remote object from a renderer that does not exist any more.
Solution - Avoid using remote or clean up your event handlers on remote objects if you have to use it
Add event remover in your code where you had added events code
window.onbeforeunload = (e) => {
win.removeAllListeners();
};
This will remove ALL listeners attached to your window before unloading it.
Note - onbeforeunload will be called before page is refreshed or closed.
Conclusion- update tutorial to adapt to solution
To reproduce-
This is not same as your tutorial but here too I am using win.on events for blur and focus and it throws errors.
https://gist.github.com/AtiqGauri/1cea1c548025faa77f9f29008ca5a5fe#file-main-js-L4
Toby56 and binaryfunt
Metadata
Metadata
Assignees
Labels
No labels
