Currently scratching my head on a tough one. I'm just starting with electron and so far so good. However, when the window gets hidden (it's a popup showing with a shortcut, that goes away when you press enter), I'd like to give the focus back to the previous window.
I'm using Mac, and the menu bar shows my previous app's name so it looks like the focus is given back to the app, but not entirely since the window is not selected.
Any idea how to fix that?
Thanks!
For Linux:
I found browserWindow.hide()
correctly restores focus.
For Windows:
browserWindow.minimize()
correctly restores focus.
For Mac:
app.hide()
correctly restores focus. Note: calling app.hide()
unfortunately hides all windows. There is no known way of keeping some windows open without hiding all with app.hide()
.
This works both on Mac, Linux and Windows:
hide() {
this.window.minimize();
this.window.hide();
if (process.platform == "darwin") this.app.hide()
}
show() {
this.window.show();
this.window.restore();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With