opener icon indicating copy to clipboard operation
opener copied to clipboard

How to open a folder on windows and focus it?

Open blarfoon opened this issue 10 months ago • 6 comments

Currently when I open a folder through explorer with open, it opens it correctly but it's not focused, the explorer window is minimized. Is there any way to bring it to focus automatically after opening?

blarfoon avatar Apr 08 '24 13:04 blarfoon

I can't reproduce this issue; on my Windows 10 PC the opened folder gets focused. What Windows version are you on?

Seeker14491 avatar Apr 08 '24 17:04 Seeker14491

Windows 11. I have a decently popular app and I get quite a few complaints about this so it's not just a me issue. Let me know if I can be of any help.

blarfoon avatar Apr 08 '24 19:04 blarfoon

I'm assuming the app in question is the new GDLauncher. I installed it, and after installing an instance and right-clicking it and selecting "Open folder", the folder did open, but it wasn't focused. It seems inconsistent though; I tried it several times, and sometimes it focuses, sometimes not. I'm thinking it's probably a kind of race condition between the click on your app focusing your app, and opener focusing the explorer window.

Seeker14491 avatar Apr 08 '24 20:04 Seeker14491

It is weird though because switching to electron's native open folder method always works. Also I would expect the explorer window to pop up but be behind GDL, not be fully minimized

blarfoon avatar Apr 09 '24 05:04 blarfoon

Both electron's method and opener go through IPC, but opener has to go through a websocket connection as well so technically it should be even slower than electron's one

blarfoon avatar Apr 09 '24 05:04 blarfoon

There's an open issue about Electron's shell.openPath() also having the issue of the window appearing in the background: https://github.com/electron/electron/issues/36765 Therefore I believe this is an Electron issue that I can't fix from my side.

Seeker14491 avatar Apr 16 '24 21:04 Seeker14491