Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I bring a window to the front, without "switching" apps in electron?

So for example lets say the user has Chrome open in full screen. Then a popup comes from the electron app, but it overlays on the chrome screen instead of switching screens to the electron app.

Like the VPN app below;enter image description here

How would i go about doing this?

like image 560
cookiekid Avatar asked Feb 01 '26 23:02

cookiekid


2 Answers

To focus a window, you can use: window.show().

If your on a mac and it's in a different workspace then it won't show. You would need to run: window.setVisibleOnAllWorkspaces(true) on the window when the window is being created then window.show() when you want it to show.

show docs

setVisibleOnAllWorkspaces docs

like image 109
Joshua Avatar answered Feb 03 '26 12:02

Joshua


I found a solution that seems to work for this! So this is assuming you've already figured out how to show a window above full screen apps in general. The issue I had with that is that when you try to bring a new window into view, it takes you out of fullscreen, even if that window is configured to show above fullscreen apps.

To deal with this the solution was simple:

mainWindow.hide()
mainWindow.show()

setTimeout(() => displayPopupWindow(data), 300)

In this case, your main window (which can be invisible) is given focus while still having the fullscreen app open, then opening the popup window will not close the fullscreen app.

like image 41
Lurein Perera Avatar answered Feb 03 '26 13:02

Lurein Perera



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!