Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS: re-open window when clicking icon after shallow-closing the app #182

Open
neopostmodern opened this issue Dec 7, 2022 · 1 comment
Labels

Comments

@neopostmodern
Copy link
Owner

No description provided.

@neopostmodern neopostmodern added this to the v0.22 milestone Dec 7, 2022
@neopostmodern
Copy link
Owner Author

Some advice by ChatGPT:

Alternatively, you can remove the window-all-closed event listener entirely, as it is not necessary for the application to function correctly. The app.quit() method will be called automatically when the last window is closed, so there is no need to handle the window-all-closed event explicitly.

Further:

To reopen the window on macOS when the user clicks the app icon again, you need to add a listener for the activate event to the app object. This event is emitted when the user clicks the app icon in the dock, and you can use it to create a new window if one does not already exist.

Here is an example of how you can add a listener for the activate event to reopen the window on macOS when the user clicks the app icon again:

app.on('activate', () => {
  // On macOS it's common to re-create a window in the app when the
  // dock icon is clicked and there are no other windows open.
  if (mainWindow === null) {
    createWindow();
  }
});

In this example, the activate event listener checks the value of the mainWindow variable. If it is null, which indicates that no window is currently open, the createWindow() function is called to create a new window.

This code should be added after the whenReady() promise is resolved, so that it is executed when the application is ready. You can do this by calling the app.on() method after the .then() method of the whenReady() promise, like this:

app
  .whenReady()
  .then(() => {
    createWindow();
    app.on('activate', () => {
      // On macOS it's common to re-create a window in the app when the
      // dock icon is clicked and there are no other windows open.
      if (mainWindow === null) {
        createWindow();
      }
    });
  })
  .catch(console.log);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant