mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: support new profile
This commit is contained in:
@@ -43,6 +43,42 @@ pub async fn import_profile(
|
||||
}
|
||||
}
|
||||
|
||||
/// new a profile
|
||||
/// append a temp profile item file to the `profiles` dir
|
||||
/// view the temp profile file by using vscode or other editor
|
||||
#[tauri::command]
|
||||
pub async fn new_profile(
|
||||
name: String,
|
||||
desc: String,
|
||||
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());
|
||||
}
|
||||
|
||||
/// Update the profile
|
||||
#[tauri::command]
|
||||
pub async fn update_profile(
|
||||
|
||||
Reference in New Issue
Block a user