mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
feat: support edit profile item
This commit is contained in:
@@ -3,11 +3,13 @@ use crate::{
|
||||
states::{ClashState, ProfilesState, VergeState},
|
||||
utils::{
|
||||
config::{read_clash, save_clash},
|
||||
dirs::app_home_dir,
|
||||
fetch::fetch_profile,
|
||||
sysopt::SysProxyConfig,
|
||||
},
|
||||
};
|
||||
use serde_yaml::Mapping;
|
||||
use std::process::Command;
|
||||
use tauri::State;
|
||||
|
||||
/// get all profiles from `profiles.yaml`
|
||||
@@ -142,6 +144,34 @@ pub fn patch_profile(
|
||||
}
|
||||
}
|
||||
|
||||
/// run vscode command to edit the profile
|
||||
#[tauri::command]
|
||||
pub fn edit_profile(index: usize, profiles_state: State<'_, ProfilesState>) -> Result<(), String> {
|
||||
let mut profiles = profiles_state.0.lock().unwrap();
|
||||
let items = profiles.items.take().unwrap_or(vec![]);
|
||||
|
||||
if index >= items.len() {
|
||||
profiles.items = Some(items);
|
||||
return Err("the index out of bound".into());
|
||||
}
|
||||
|
||||
let file = items[index].file.clone().unwrap_or("".into());
|
||||
profiles.items = Some(items);
|
||||
|
||||
let path = app_home_dir().join("profiles").join(file);
|
||||
if !path.exists() {
|
||||
return Err("failed to open the file".into());
|
||||
}
|
||||
|
||||
match which::which("code") {
|
||||
Ok(code) => match Command::new(code).arg(path).status() {
|
||||
Ok(_) => Ok(()),
|
||||
Err(_) => Err("failed to open file by VScode".into()),
|
||||
},
|
||||
Err(_) => Err("please install VScode for edit".into()),
|
||||
}
|
||||
}
|
||||
|
||||
/// restart the sidecar
|
||||
#[tauri::command]
|
||||
pub fn restart_sidecar(
|
||||
|
||||
Reference in New Issue
Block a user