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

Cannot open files by system default application (VS Code) #105

Open
Myriad-Dreamin opened this issue Nov 17, 2024 · 2 comments
Open

Cannot open files by system default application (VS Code) #105

Myriad-Dreamin opened this issue Nov 17, 2024 · 2 comments

Comments

@Myriad-Dreamin
Copy link

Myriad-Dreamin commented Nov 17, 2024

Context: Myriad-Dreamin/tinymist#837

I want to have a robust way to open files by system default application. I simply use open crate by:

log::info!("open with system default apps: {path:?}");
if let Err(e) = ::open::that_detached(path) {
    log::error!("failed to open with system default apps: {e}");
};

At first glance, it worked well when I set default application as Adobe Acrobat or Edge. But I saw node-package-open's limitation,

This extension use two ways to open file in external applications.

1. Node package: open

This package has one limit that can't open a file which is also made by electron. For example, you can't open md file in typora using this package. The openCommand, args configuration item is also supported by this package. When isElectronApp: false(by default), extension will use this way.

I was interested in checking whether our implementation worked in the case. Then I set the default application to "Visual Studio Code".

image

❎ But unluckily, it silently failed.

  • ✅ I then double clicked the pdf file, explorer helped me to open the file in "Visual Studio Code".

  • ✅ I also ran the command in console, it worked:

    cmd /c start "" "c:\\Users\\xxx\\test.pdf"
    
  • ❎ I have also tested opener, they silently failed as well.

@Myriad-Dreamin
Copy link
Author

Inspired from #75, I finally made it work by:

#[cfg(not(target_os = "windows"))]
let do_open = ::open::that_detached;
#[cfg(target_os = "windows")]
fn do_open(path: impl AsRef<std::ffi::OsStr>) -> std::io::Result<()> {
    ::open::with_detached(path, "explorer")
}

@Byron
Copy link
Owner

Byron commented Nov 17, 2024

Thanks a lot for the detailed description of the problem!

One would think it's easy to open something with the default application consistently, but apparently not.

I think there have been many iterations on this code already, at some point it might even have used explorer but it ran into other limitations.
Thus I am not sure there is "the one working way", but wouldn't give up hope just yet either.

@Byron Byron added enhancement and removed bug labels Nov 17, 2024
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

2 participants