fix: windows cannot open yaml file

This commit is contained in:
huzibaca 2024-11-23 19:46:53 +08:00
parent d6f5a79ac9
commit be719680b0
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302

View File

@ -101,7 +101,15 @@ pub fn get_last_part_and_decode(url: &str) -> Option<String> {
/// open file
/// use vscode by default
pub fn open_file(app: tauri::AppHandle, path: PathBuf) -> Result<()> {
app.shell().open(path.to_string_lossy(), None).unwrap();
#[cfg(target_os = "macos")]
let code = "Visual Studio Code";
#[cfg(not(target_os = "macos"))]
let code = "code";
if let Err(err) = open::with(&path.as_os_str(), code) {
log::error!(target: "app", "Can not open file with VS code, {}", err);
// default open
app.shell().open(path.to_string_lossy(), None)?;
};
Ok(())
}