Skip to content

avoid using openExternal for file URIs on Windows - #13926

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/windows-open-external
Nov 13, 2023
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/windows-open-external

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Addresses #13886.

Approach

It appears that Electron's shell.openExternal() struggles with certain kinds of Windows paths. This PR falls back to using our trusty friend ShellExecute() to open these files.

Automated Tests

N/A

QA Notes

Test via notes in #13886.

Documentation

N/A

Checklist

  • If this PR adds a new feature, or fixes a bug in a previously released version, it includes an entry in NEWS.md
  • If this PR adds or changes UI, the updated UI meets accessibility standards
  • A reviewer is assigned to this PR (if unsure who to assign, check Area Owners list)
  • This PR passes all local unit tests

@kevinushey
kevinushey requested a review from gtritchie November 13, 2023 23:28

@gtritchie gtritchie left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment about a comment, but otherwise LGTM!

Oh, also be sure to add to NEWS.

ipcMain.on('desktop_browse_url', (event, url: string) => {

// shell.openExternal() doesn't handle file URIs containining non-ASCII characters
// shell.openExternal() seems unreliable on Windows

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be tracked (more or less) via electron/electron#31347, maybe add that in the comment in case we want to revisit someday and see if it has been fixed?

@kevinushey
kevinushey merged commit f74629c into main Nov 13, 2023
@kevinushey
kevinushey deleted the bugfix/windows-open-external branch November 13, 2023 23:39
jennybc added a commit to posit-dev/positron that referenced this pull request Oct 20, 2025
Addresses #9985

This fixes `UiFrontendEvent.OpenWithSystem`, which is experienced as
`browseURL()` working in R for local filepaths that contain non-ascii
characters, on Windows.

Here's a screenshot of executing `browseURL("tütü")` on Windows, where
there is a local folder named "tütü". And it now dutifully opens in the
Windows file explorer.

<img width="1388" height="608" alt="Screenshot 2025-10-20 110409"
src="https://github.com/user-attachments/assets/dd4771ec-fcf8-4830-934a-c5e36e68e261"
/>

Before this fix the result looked like so:

<img width="593" height="255" alt="Screenshot 2025-10-17 142907"
src="https://github.com/user-attachments/assets/140d40b8-b54c-41aa-832d-8f657ab29138"
/>

`UiFrontendEvent.OpenWithSystem` ultimately routes into
`NativeHostMainService.doOpenShellExternal()` which previously called
(only) electron's `shell.openExternal()`, which is really designed for
URLs, but also works for filepaths in many cases. However, on Windows,
`shell.openExternal()` falls over for local filepaths with non-ascii
characters and the recommended solution is to use `shell.openPath()`
instead which really is meant exactly for this: "Open the given file in
the desktop's default manner."

Related links:

* Main issue for this in electron:
<electron/electron#6302>
* Another report of same in electron:
<electron/electron#31347>
* VS Code issue that effectively tracks this problem:
<microsoft/vscode#85930>
* Same problem affecting RStudio:
<rstudio/rstudio#12467>
* How RStudio solved it: <rstudio/rstudio#13926>
* Related discussion/fix in another project that I found helpful:
<laurent22/joplin#4804 (comment)>

### Release Notes

<!--
Optionally, replace `N/A` with text to be included in the next release
notes.
The `N/A` bullets are ignored. If you refer to one or more Positron
issues,
these issues are used to collect information about the feature or
bugfix, such
as the relevant language pack as determined by Github labels of type
`lang: `.
  The note will automatically be tagged with the language.

These notes are typically filled by the Positron team. If you are an
external
  contributor, you may ignore this section.
-->

#### New Features

- N/A

#### Bug Fixes

- N/A


### QA Notes

<!--
Positron team members: please add relevant e2e test tags, so the tests
can be
  run when you open this pull request.

- Instructions:
https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags
- Available tags:
https://github.com/posit-dev/positron/blob/main/test/e2e/infra/test-runner/test-tags.ts
-->


<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->
seeM pushed a commit to posit-dev/positron that referenced this pull request Oct 21, 2025
Addresses #9985

This fixes `UiFrontendEvent.OpenWithSystem`, which is experienced as
`browseURL()` working in R for local filepaths that contain non-ascii
characters, on Windows.

Here's a screenshot of executing `browseURL("tütü")` on Windows, where
there is a local folder named "tütü". And it now dutifully opens in the
Windows file explorer.

<img width="1388" height="608" alt="Screenshot 2025-10-20 110409"
src="https://github.com/user-attachments/assets/dd4771ec-fcf8-4830-934a-c5e36e68e261"
/>

Before this fix the result looked like so:

<img width="593" height="255" alt="Screenshot 2025-10-17 142907"
src="https://github.com/user-attachments/assets/140d40b8-b54c-41aa-832d-8f657ab29138"
/>

`UiFrontendEvent.OpenWithSystem` ultimately routes into
`NativeHostMainService.doOpenShellExternal()` which previously called
(only) electron's `shell.openExternal()`, which is really designed for
URLs, but also works for filepaths in many cases. However, on Windows,
`shell.openExternal()` falls over for local filepaths with non-ascii
characters and the recommended solution is to use `shell.openPath()`
instead which really is meant exactly for this: "Open the given file in
the desktop's default manner."

Related links:

* Main issue for this in electron:
<electron/electron#6302>
* Another report of same in electron:
<electron/electron#31347>
* VS Code issue that effectively tracks this problem:
<microsoft/vscode#85930>
* Same problem affecting RStudio:
<rstudio/rstudio#12467>
* How RStudio solved it: <rstudio/rstudio#13926>
* Related discussion/fix in another project that I found helpful:
<laurent22/joplin#4804 (comment)>

### Release Notes

<!--
Optionally, replace `N/A` with text to be included in the next release
notes.
The `N/A` bullets are ignored. If you refer to one or more Positron
issues,
these issues are used to collect information about the feature or
bugfix, such
as the relevant language pack as determined by Github labels of type
`lang: `.
  The note will automatically be tagged with the language.

These notes are typically filled by the Positron team. If you are an
external
  contributor, you may ignore this section.
-->

#### New Features

- N/A

#### Bug Fixes

- N/A


### QA Notes

<!--
Positron team members: please add relevant e2e test tags, so the tests
can be
  run when you open this pull request.

- Instructions:
https://github.com/posit-dev/positron/blob/main/test/e2e/README.md#pull-requests-and-test-tags
- Available tags:
https://github.com/posit-dev/positron/blob/main/test/e2e/infra/test-runner/test-tags.ts
-->


<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants