Skip to content

Commit

Permalink
fix: not open file when new profile
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzgydi committed Feb 14, 2022
1 parent 78a0cfd commit 66bf4ba
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src-tauri/src/cmds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,8 @@ pub async fn new_profile(
profiles_state: State<'_, ProfilesState>,
) -> Result<(), String> {
let mut profiles = profiles_state.0.lock().unwrap();

let (_, path) = profiles.append_item(name, desc)?;

if !path.exists() {
return Err("the file not found".into());
}

// use vscode first
if let Ok(code) = which::which("code") {
return match Command::new(code).arg(path).status() {
Ok(_) => Ok(()),
Err(_) => Err("failed to open file by VScode".into()),
};
}

// use `open` command
if let Ok(open) = which::which("open") {
return match Command::new(open).arg(path).status() {
Ok(_) => Ok(()),
Err(_) => Err("failed to open file by `open`".into()),
};
}

return Err("failed to open the file, please edit the file manually".into());
profiles.append_item(name, desc)?;
Ok(())
}

/// Update the profile
Expand Down

0 comments on commit 66bf4ba

Please sign in to comment.