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

Event when app is becoming active #2444

Closed
ialexryan opened this issue Aug 7, 2015 · 10 comments
Closed

Event when app is becoming active #2444

ialexryan opened this issue Aug 7, 2015 · 10 comments

Comments

@ialexryan
Copy link
Contributor

Steps to reproduce:

  • hide or close all windows of your app.
  • switch away from your app
  • Cmd+Tab back to your app

Issue: the "activate-with-no-open-windows" event is only triggered if I return to the app by clicking on the dock icon, not by Cmd+Tab'ing.

@ialexryan
Copy link
Contributor Author

This looks like it might be relevant: http://cocoadev.com/DifferentTypesOfAppActivation

@zcbenz
Copy link
Contributor

zcbenz commented Aug 24, 2015

This is expected since the term "activate" on OS X means the application is activated by clicking on the dock icon, what you want should be a new "active" or "focus" event that emitted when application is becoming active by Cmd+Tab or other means.

@zcbenz zcbenz changed the title activate-with-no-open-windows not fired on Cmd+Tab Event when app is become active Aug 24, 2015
@zcbenz zcbenz changed the title Event when app is become active Event when app is becoming active Aug 24, 2015
@zcbenz
Copy link
Contributor

zcbenz commented Sep 17, 2015

This has been fixed by adding the activate event.

@zcbenz zcbenz closed this as completed Sep 17, 2015
@ialexryan
Copy link
Contributor Author

@zcbenz Wait, sorry - how does that fix it? I just checked, and the activate event is not called when I Cmd+Tab to my application. Please reopen the issue.

@loki951753
Copy link

I just checked, and the activate event is not called when I Cmd+Tab to my application.

same problem as @ialexryan

@moonwave99
Copy link

Had same problem, just checked what Atom does.

@ialexryan
Copy link
Contributor Author

Can this be reopened? My understanding is that my original issue still stands, although I'm no longer in a position to conveniently verify this with the latest Electron build.

@akashnimare
Copy link

akashnimare commented Aug 9, 2016

@ialexryan @moonwave99 @loki951753 It's there on latest build. Btw no application provide this feature. This issue exists even on telegram app (built on objective c). Same goes with chrome. So I guess this is standard behaviour (activate app only on click not on cmd+tab).

Temporary fix - Start tabbing with Cmd-Tab until you get to the application you want to switch to, then press and hold Option before releasing Cmd-Tab. More info
http://apple.stackexchange.com/questions/29705/cmdtab-switches-to-the-correct-space-but-doesnt-bring-app-up-to-front

@chriswhong
Copy link

Hello, for anyone who stumbles across this, I was also seeing that the activate event only fired when switching back to my app by clicking on the dock, and did not fire when using Cmd-Tab.

I wanted my electron to open its only window when the user brings the app back to the foreground. I noticed that github desktop uses this approach, and it worked for me. You have to use Menu.sendActionToFirstResponder:

      mainWindow.on('close', (e) => {
        if (!forceQuit) {
          e.preventDefault()
          Menu.sendActionToFirstResponder('hide:')
        }
      })

Where forceQuit is true if they are actually quitting the app, not just closing the window.

@emcmanus
Copy link

As explained above, the activate event works correctly. You're not supposed to "launch" applications from the app switcher.

There are two ways to fix the UX.

  1. Exit the process when all windows are closed:
app.on('window-all-closed', () => {
  app.quit()
});
  1. Or, if you'd like to keep the main thread running, even though no windows are visible:
// Hide our icon from the MacOS app switcher when there is no window to show.
app.on('browser-window-created', () => {
  app.dock.show(); // Show in app switcher
});
app.on('window-all-closed', () => {
  app.dock.hide(); // Hide from app switcher
});
app.on('activate', () => {
  // User has clicked the dock icon. Do whatever you need to, to create and/or show your main window.
});

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

No branches or pull requests

7 participants