Skip to content
Snippets Groups Projects
Unverified Commit ec0fdf83 authored by GyDi's avatar GyDi Committed by GitHub
Browse files

feat: change open command on linux

refactor(logging): refine open dir failed log message, add Linux support
parents 8890051c cb94d841
No related branches found
No related tags found
No related merge requests found
...@@ -6,7 +6,7 @@ use crate::{ ...@@ -6,7 +6,7 @@ use crate::{
use crate::{ret_err, wrap_err}; use crate::{ret_err, wrap_err};
use anyhow::Result; use anyhow::Result;
use serde_yaml::Mapping; use serde_yaml::Mapping;
use std::{path::PathBuf, process::Command}; use std::{path::PathBuf, process::Command, process::Stdio};
use tauri::{api, Manager, State}; use tauri::{api, Manager, State};
/// get all profiles from `profiles.yaml` /// get all profiles from `profiles.yaml`
...@@ -323,24 +323,53 @@ pub fn open_logs_dir() -> Result<(), String> { ...@@ -323,24 +323,53 @@ pub fn open_logs_dir() -> Result<(), String> {
/// get open/explorer command /// get open/explorer command
fn open_path_cmd(dir: PathBuf, err_str: &str) -> Result<(), String> { fn open_path_cmd(dir: PathBuf, err_str: &str) -> Result<(), String> {
let result;
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
use std::os::windows::process::CommandExt; use std::os::windows::process::CommandExt;
if let Err(err) = Command::new("explorer") result = Command::new("explorer")
.creation_flags(0x08000000) .creation_flags(0x08000000)
.arg(dir) .arg(&dir)
.spawn() .spawn();
{ }
log::error!("{err}");
return Err(err_str.into()); #[cfg(target_os = "macos")]
} {
result = Command::new("open").arg(&dir).spawn();
}
#[cfg(target_os = "linux")]
{
result = Command::new("xdg-open").arg(&dir).stdout(Stdio::piped()).stderr(Stdio::piped()).spawn();
} }
#[cfg(not(target_os = "windows"))] match result {
if let Err(err) = Command::new("open").arg(dir).spawn() { Ok(child) => {
log::error!("{err}"); match child.wait_with_output() {
return Err(err_str.into()); Ok(out) => {
if let Some(code) = out.status.code() {
if code != 0 {
log::error!("open dir {:?} failed, child exit code: {:?}, stderr: {:?} stdout: {:?}",
&dir, code, String::from_utf8_lossy(&out.stderr), String::from_utf8_lossy(&out.stdout));
return Err(err_str.into());
}
}
},
Err(err) => {
log::error!("open dir {:?} failed, child exec err: {}", &dir, err);
return Err(err_str.into());
}
}
},
Err(err) => {
log::error!("open dir {:?} spawn process failed, err: {}", &dir, err);
return Err(err_str.into());
},
_ => {
log::error!("open dir {:?} failed due to OS not supported", &dir);
return Err(err_str.into());
},
} }
return Ok(()); return Ok(());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment