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

vscode.env.openExternal opens a given file in Theia rather than in an external app #13535

Closed
Tracked by #13192
chroberino opened this issue Mar 27, 2024 · 10 comments
Closed
Tracked by #13192

Comments

@chroberino
Copy link

Bug Description:

I guess vscode.env.openExternal in Theia should do the same as in VS Code, i.e. use the OS' default application for opening a given URI. I was trying to use this call in a VS Code extension and observed that in Theia files are always be opened within Theia (while in VS Code they open in external apps).

Steps to Reproduce:

  1. Create a VS Code extension:

    • In package.json of your VS Code extension create a command like
      { "command": "myextension.open-in-external-app", "title": "Open in External App" }
    • Implement this command by invoking vscode.env.openExternal, aiming to open the currently chosen file in its default app (as configured in the OS).
  2. When using your VS Code extension in Theia select a file in the Explorer and pick the "Open in External App" command from the command palette

  3. Unexpectedly, the file will be opened within Theia, not in an external app.

As an easy alternative (without any coding efforts) you could also reproduce this issue with the Open in External App extension: If you don't give it any specific configuration, it will utilize vscode.env.openExternal striving to open a given file URI in its default application. However, the result is the same as described above, the file will not be opened in an external app but within Theia.

Additional Information

  • Operating System: Windows 10
  • Theia Version:
@dhuebner
Copy link
Member

@chroberino
Are you also missing the "Open in External App" file browser menu contribution after installing Open in External App extension?
I see the command in the palette, but not the menu entry...

@dhuebner
Copy link
Member

Right now theia.env.openExternal() is called when the vscode.env.openExternal is triggered. This calls windowStateExt.openUri(uri) and its current implementation just redirects to the opener-service.ts without providing any further information except the URI. The only handler that matches is the EditorPreview so the file is opened in Theia. I also didn't found a registered handler that can call external applications. In electron case such a handler should probably call shell.openPath(fsPath) to redirect to the OS editors.

@dhuebner
Copy link
Member

Maybe we could also offer Open With... -> System Editor in Theia?

@chroberino
Copy link
Author

@chroberino Are you also missing the "Open in External App" file browser menu contribution after installing Open in External App extension? I see the command in the palette, but not the menu entry...

It's the same for me: I don't get this item in the context menu but only the entry in the command palette.
I have already created an issue for this: tjx666/open-in-external-app#63

@dhuebner
Copy link
Member

@chroberino
Menu contribution works in vs-code, so might be a problem with Thiea. We should investigate what goes wrong there.

@JonasHelming
It is not related to the vscode.env.openExternal handling problem, but I did some experiments with the new OpenWithService and could contribute a new built-in "open handler" that redirects to the operation system.

Bildschirmfoto 2024-04-12 um 15 06 50

@chroberino
Copy link
Author

Menu contribution works in vs-code, so might be a problem with Thiea. We should investigate what goes wrong there.

I am far from being a deep-water-diver in Eclipse Theia. I am rather just learning to swim...

But I can quickly contribute to following snippet as an insight from the package.json file of the "Open in External App" extension:

   "contributes": {
       "commands": [
           {
               "command": "openInExternalApp.open",
               "title": "%cmd.open%"
           },
           {
               "command": "openInExternalApp.openMultiple",
               "title": "%cmd.openMultiple%"
           }
       ],
       "menus": {
           "explorer/context": [
               {
                   "when": "!explorerResourceIsFolder && isFileSystemResource",
                   "command": "openInExternalApp.open",
                   "alt": "openInExternalApp.openMultiple",
                   "group": "navigation@10"
               }
           ],
           "editor/title/context": [
               {
                   "when": "isFileSystemResource",
                   "command": "openInExternalApp.open",
                   "alt": "openInExternalApp.openMultiple",
                   "group": "navigation@10"
               }
           ]
       }
   }

https://github.com/tjx666/open-in-external-app/blob/main/package.json

Maybe this offers some obvious hints?
Maybe the when condition is not true in Theia?
Maybe the alt or group confuses Theia?

@dhuebner
Copy link
Member

@chroberino
Okay, thanks! I will check why the contribution doesn't work.

@dhuebner
Copy link
Member

@chroberino
Yes, it looks like Theia is missing context key handling for isFileSystemResource

@JonasHelming
Copy link
Contributor

@dhuebner Is this solved with your PR?

@dhuebner
Copy link
Member

@JonasHelming
Yes, should be fixed. To check, try the new 'System Editor' opener in Theia electron.

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

No branches or pull requests

4 participants