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

[Feature Request] gui.App.hide() or gui.App.blur() #2241

Closed
2 of 3 tasks
dillonkrug opened this issue Aug 24, 2014 · 4 comments
Closed
2 of 3 tasks

[Feature Request] gui.App.hide() or gui.App.blur() #2241

dillonkrug opened this issue Aug 24, 2014 · 4 comments
Labels

Comments

@dillonkrug
Copy link

I know about gui.Window.get().hide(), but there is no corresponding gui.App.hide() method.

the setup I'm trying to implement is basically Alfred's interface:

  • App starts hidden — "window": { "show": false } in package.json
  • Global shortcut brings up overlay — App.registerGlobalHotKey() and "always-on-top": true
  • Repeating the shortcut should hide the overlay and return control to previous application

It's the last bit that doesn't seem to be possible at the moment. I can hide the window, but focus remains on the node-webkit application. I have to click on whatever application I was working in before to return the focus.

on a mac, hiding the application will revert focus back to whatever the previously used application was, so I'm guessing this is the easiest solution.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@Egnus
Copy link

Egnus commented Aug 25, 2014

I think you can't control focus on other app outside node context.
That means you can hide the actual but not the focus the other.

In case everything is in node context. A window opening another window for example, you can control events of the overlayed window (the second one) like "hidden" status. to get focus on other windows (the first window for example).
EDITED
Think on this as a controller window for your app.

  • main.html control the rest of the windows (this is always hidden).
  • programA.html has your app, you control it behaviours with main.html (on.hidden, on.closing, on.closed..)
  • programB.html has your overlayed window (and advertisment for example). you open it with main.html(maybe a custom event triggered in programA catched by main.html) and when it closes or hidden you catch that event and return focus to programA. (you can do the same from programA to programB without main.html).

For 3rd party apps. (Outside Node-webkit)
In windows, if you hide the overlayed node app, you can see the last app opened at the top, but without focus (you need to do alt+tab or click to focus it).
In this case you are requesting something different than in your tittle, you are looking for a gui.Window.get().focus() API to work in the last window that the system had focus, inside or outside node. I dont know, maybe it is possible, but remember to change tittle and be more specific with it.

I hope this helps you a bit, and someone gives you what you need if so. :D

@dillonkrug
Copy link
Author

Yes, I would suppose that application focus is handled at the os level and may be tricky to implement in a cross-platform manner. For example, it would be ideal, but I don't know that it would be possible to implement something like this:

var focused = false,
    previousApp = null,
    overlay = gui.Window.get();

gui.App.registerGlobalHotKey(new gui.Shortcut({
    key: 'Some+Short+Cut',
    active: function(event) {
        // currently there is no "event" passed in.
        focused = !focused;

        if (focused) {
            previousApp = event.previouslyFocusedAppliction;
            overlay.show();
            overlay.focus();
        } else {
            overlay.blur();
            overlay.hide();
            if (previousApp) {
                // this doesn't exist...
                gui.System.focus(previousApp);
                previousApp = null;
            }
        }
    },
    failed: function() {}
}));

That would be a versatile solution for focusing arbitrary third-party apps. That said, all I need to is to focus the previous application, and (at least on a mac) "hiding" an application automatically does that.

var focused = false,
    overlay = gui.Window.get();

gui.App.registerGlobalHotKey(new gui.Shortcut({
    key: 'Some+Short+Cut',
    active: function(event) {
        // currently there is no "event" passed in.
        focused = !focused;

        if (focused) {
            overlay.show();
            overlay.focus();
        } else {
            gui.App.hide();
        }
    },
    failed: function() {}
}));

If the concept of application-level "hide" doesn't translate to other platforms, I imagine App.hide() would simply hide all of the application's windows.

@geoah
Copy link

geoah commented Feb 17, 2015

Has there been any progress on this or at least a workaround to actually be able to blur the window and re-focus the previous application?

Thanks~ :)

@stale
Copy link

stale bot commented Sep 30, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Sep 30, 2017
@stale stale bot closed this as completed Oct 2, 2017
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

3 participants