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

shell.openItem should activate the opened app #10477

Closed
sindresorhus opened this issue Sep 9, 2017 · 6 comments
Closed

shell.openItem should activate the opened app #10477

sindresorhus opened this issue Sep 9, 2017 · 6 comments

Comments

@sindresorhus
Copy link
Contributor

  • Electron version: 1.7.7
  • Operating system: macOS 10.12.6

Expected behavior

For example, if I ask it to open a path to a directory, it should open it in Finder and focus the Finder window.

Actual behavior

It opens the Finder window in the background and my app window is still focused.

How to reproduce

shell.openItem('path/to/some/dir/');

Focusing the opened app is expected behavior on macOS and should at least be an option.

The shell.openExternal method has this, so it's clear you agree. We just need the behavior/option added to this method too.

@MarshallOfSound
Copy link
Member

Afaik this is because our implementation of openItem on macOS doesn't use NSWorkspace rather the now deprecated AE api's. This is due to a number of bugs with alternate implementations.

https://github.com/electron/electron/blob/master/atom/common/platform_util_mac.mm#L127

If you want to open it with activation I believe you can just pass the file path to openExternal

@sindresorhus
Copy link
Contributor Author

/atom/common/platform_util_mac.mm@master#L127

The first mentioned issue there is fixed in Chromium. They're using NSWorkspace now: https://cs.chromium.org/chromium/src/chrome/browser/platform_util_mac.mm?l=30&rcl=975794ee43d7036fb94be988a9f6751db85c7a3a

If you want to open it with activation I believe you can just pass the file path to openExternal

Yes, that's my workaround, but it's ugly as it requires converting the path to a file URL.

@codebytere
Copy link
Member

👋 @sindresorhus this fix is now in master, so i'm going to go ahead and close this issue!

@sindresorhus
Copy link
Contributor Author

@codebytere Thank you for fixing this 🙌

@stanleyxu2005
Copy link

I noticed this bug for long time. And I can confirm it is still buggy for Windows 7 with (latest) Electron 8.2.0

@n-smits
Copy link

n-smits commented Apr 16, 2020

Works great on mac, but how about making it optional? :')
Boolean: should the app be activated (if the item was successfully opened), default true.

Use case: dev experience - working on a file exporter and would love to see the file live reload -- without having to cmd-tab back to the editor.

I suspect a work-around is possible through shell.openExternal as it has activate bool option.

As of now, it's possible just to omit the line (don't do any file opening) but keep the file open -> after saving in the editor, (vue on mounted) is hot reloaded and the file is overwritten, though to see changes you need to cmd-tab to refresh it.

niik added a commit to desktop/desktop that referenced this issue Dec 16, 2020
The issue described in #2968 (comment) doesn't appear to exist any more and the openExternal solution fails when opening paths that ends with a backslash.

I'd bet the issue we were seeing  was  electron/electron#10477 which has been long since resolved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants