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 on CommandOrControl+Tab click #9577

Closed
andrewfan opened this issue May 24, 2017 · 6 comments
Closed

Event on CommandOrControl+Tab click #9577

andrewfan opened this issue May 24, 2017 · 6 comments
Labels

Comments

@andrewfan
Copy link

I'm working on the application that should appear on the shortcut click. Once user press shortcut I'm toggling window visibility with show\hide methods.

My problem is when window was hidden by shortcut and the user pressed Cmd-Tab i have no event to be able to show the window.

I found similar issue here #2444 it is closed but activate event does not solve the problem (it is simply not firing) also i fond the same issue here
https://discuss.atom.io/t/how-to-detect-the-activation-of-an-electron-window-on-macos-via-cmd-tab/39442

@tkambler
Copy link

A follow-up post has been left in the discussion thread that you referenced. Apparently you can tap into the browser-window-focus event. I have not had time to test this yet, but it sounds promising.

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

@tkambler
Copy link

Checking the browser-window-focus event out, and this does not appear to solve this need.

@tkambler
Copy link

@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()) {
            Menu.sendActionToFirstResponder('hide:');
        } else {
            mainWindow.show();
        }
    });

@andrewfan
Copy link
Author

@tkambler I'm doing exactly the same and it still does not work for me. For now, I just removed my app from the dock and it made app disappear from app switcher.

@tkambler
Copy link

tkambler commented Jun 1, 2017

@andrewfan Here is the sample app in which I implemented this. cd into the app dir, npm install, then npm start. Shortcuts are defined in app/lib/main/window.js.

@codebytere
Copy link
Member

Closing as stale and seemingly resolved.

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

4 participants