Electron Windows app close not ending threads

Viewed 7831

I have an Electron app, running on Windows, it has a few controls on the main window and a cancel button. I notice when it is running I see two threads, I assume the main and renderer threads. When the cancel button is clicked the renderer sends an IPC message to the main thread and the main thread calls app.quit. Under these conditions the two threads end. If I right click on the icon in the Windows taskbar for the app and select "Close" the threads only end when the app is run under the VSCode debugger, when the app is run without the debugger and the same is done the two threads remain.

How can I debug this? Any suggestions as to why it is happening.

Under the debugger I see the close being caught in the main thread and app.quit is called.

UPDATE: Since the app used Electron 1.7.9 I have updated it to use 2.0.8 just in case this was an issue that had been addressed. However, with 2.0.8 the issue remains.

Sid

1 Answers

Thanks to some input from the Electron Slack community I have resolved this issue. My mistake was in the way I was calling the app.quit() method.

My code was handling the MainWindow on "close" event and executing the app.quit() method in that event handler.

The correct way to close the app is to handle the app "window-all-closed" event and execute the app.quit() method there.

Here is a gist of a skeleton main.js for an Electron app that was sent to me to help me resolve the issue.

https://gist.github.com/sidprice/612cb49cec923eeb94cfcddf1736c181

Sid

Related