mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2024-11-16 11:42:21 +08:00
feat: put profile works
This commit is contained in:
parent
83c0bde22b
commit
f736951fc8
|
@ -4,7 +4,11 @@ use crate::{
|
|||
emit::ClashInfoPayload,
|
||||
state::{ClashInfoState, ProfileLock},
|
||||
},
|
||||
utils::{app_home_dir, clash, fetch::fetch_profile},
|
||||
utils::{
|
||||
app_home_dir,
|
||||
clash::{self, put_clash_profile},
|
||||
fetch::fetch_profile,
|
||||
},
|
||||
};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
@ -135,27 +139,35 @@ pub fn set_profiles(
|
|||
|
||||
#[tauri::command]
|
||||
/// change to target profile
|
||||
pub fn put_profiles(current: usize, lock: State<'_, ProfileLock>) -> Result<(), String> {
|
||||
pub async fn put_profiles(
|
||||
current: usize,
|
||||
lock: State<'_, ProfileLock>,
|
||||
clash_info: State<'_, ClashInfoState>,
|
||||
) -> Result<(), String> {
|
||||
match lock.0.lock() {
|
||||
Ok(_) => {}
|
||||
Err(_) => return Err(format!("can not get file locked")),
|
||||
};
|
||||
|
||||
let mut profiles = read_profiles();
|
||||
let clash_info = match clash_info.0.lock() {
|
||||
Ok(arc) => arc.clone(),
|
||||
_ => return Err(format!("can not get clash info")),
|
||||
};
|
||||
|
||||
let mut profiles = read_profiles();
|
||||
let items_len = match &profiles.items {
|
||||
Some(p) => p.len(),
|
||||
None => 0,
|
||||
};
|
||||
|
||||
if current >= items_len {
|
||||
Err(format!(
|
||||
return Err(format!(
|
||||
"failed to change profile to the index `{}`",
|
||||
current
|
||||
))
|
||||
} else {
|
||||
));
|
||||
}
|
||||
|
||||
profiles.current = Some(current as u32);
|
||||
save_profiles(&profiles);
|
||||
Ok(())
|
||||
}
|
||||
put_clash_profile(&clash_info).await
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user