How to detect the "activation" of an Electron window on MacOS via CMD + TAB?


I have a MacOS app that defines a key combo shortcut. When pressed, the app hides / shows itself via window.hide() / Imagine for a moment that the app has been hidden via this shortcut. If the user clicks the app dock icon, I know to show the app, because I am watching for the app’s activate event. But… so far as I can tell, no similar event exists for when the user brings the app into “focus” via CMD + TAB. When I do this, the app’s menu is given focus at the top of the screen, but I’m unable to detect an event that would tell me that I need to show the window again.

Has anyone else dealt with this before?


@tkambler hey, I faced the same issue, did you figured out it somehow?


No, unfortunately. If you do, would you please let me know?


i created an issue hope somebody will help us :slight_smile:


app.on(“browser-window-focus”, () => {
//This occurs when any window in the app gains focus.


This does not appear to work.


@andrewfan I have the answer we’ve been looking for. For reference, see this issue.

The trick is to not hide your application’s window, but rather to hide the entire application itself via Window.sendActionToFirstResponder:

    globalShortcut.register('CommandOrControl+Alt+X', () => {
        if (mainWindow.isVisible()) {
        } else {