Skip to content
Advertisement

Only hide the window when closing it [Electron]

I try to hide my main window so that I hasn’t to load again later. I got the following code:

JavaScript

So that’s not working for me, when I close the window I get this error message: enter image description here

Can somebody help me? Line 37 is the line with win.hide()

Thank you!

Advertisement

Answer

Use the close event instead of the closed event.

When the closed event is fired the window is already closed.

When the close event is fired the window is still open and you can prevent it from closing by using event.preventDefault(); like this:

JavaScript

However on MacOS that’ll stop you from quitting your app. To allow quitting your app and preventing windows from closing use this code:

JavaScript

That’ll only stop the window from closing if the app isn’t quitting.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement