Seeker14491 / opener

Open a file or link in the system default program.
Apache License 2.0
49 stars 10 forks source link

How to open a folder on windows and focus it? #30

Open blarfoon opened 3 months ago

blarfoon commented 3 months ago

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?

Seeker14491 commented 3 months ago

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

blarfoon commented 3 months ago

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.

Seeker14491 commented 3 months ago

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.

blarfoon commented 3 months ago

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 commented 3 months ago

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

Seeker14491 commented 2 months ago

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.