Hide the window when you press the close button on the electron app for Mac OSX

Asked 2 months ago, Updated 2 months ago, 6 views

Creating an electron app for Mac OSX.
I don't want to close the app when I press the close button, but like other Mac apps, I want to hide the window, but I don't know how to do it.

Even if you press the close button, if you exit the application from Menu Quit, or if you shut down the OS and force the application to exit, all browser-window close events are called, so you cannot determine whether the application is closed or hidden.

Is there a way to determine why the close event occurred?

electron

2022-09-30 11:49

1 Answers

By default, when you press the close button, the browserWindow quit event is called, but the app quit event does not occur.
App-side quit events are called when the app ends, such as Cmd+Q.

Electron app events are officially well written.
http://electron.atom.io/docs/v0.36.8/api/app/ #events

If the questioner receives everything he wants to do as if he doesn't want to close the app itself even if he closes the window, that's the default.If not, please review your code.You should have shut down the app when you closed the window.

If you want to display the window again when you click Dock, like other apps, why don't you get the event when the electron is activated and generate the window again?

app.on('activate', function(){
  if(mainWindow==null){
    mainWindow = new BrowserWindow();
  }
});

If you don't want the state to return to its initial state, you can save the state of the app when you close it (you can get the event when you close it) and write a code that restores the state when you regenerate the window.


2022-09-30 11:49

If you have any answers or tips


© 2022 OneMinuteCode. All rights reserved.