feat: handle remote clash config fields

This commit is contained in:
GyDi
2022-04-07 01:20:44 +08:00
parent 6ade0b2b1a
commit fd99ba6255
7 changed files with 146 additions and 7 deletions

View File

@@ -125,6 +125,23 @@ pub fn change_profile_chain(
wrap_err!(clash.activate_enhanced(&profiles, false, false))
}
/// change the profile valid fields
#[tauri::command]
pub fn change_profile_valid(
valid: Option<Vec<String>>,
app_handle: tauri::AppHandle,
clash_state: State<'_, ClashState>,
profiles_state: State<'_, ProfilesState>,
) -> Result<(), String> {
let mut clash = clash_state.0.lock().unwrap();
let mut profiles = profiles_state.0.lock().unwrap();
profiles.put_valid(valid);
clash.set_window(app_handle.get_window("main"));
wrap_err!(clash.activate_enhanced(&profiles, false, false))
}
/// manually exec enhanced profile
#[tauri::command]
pub fn enhance_profiles(

View File

@@ -316,6 +316,9 @@ pub struct Profiles {
/// same as PrfConfig.chain
chain: Option<Vec<String>>,
/// record valid fields for clash
valid: Option<Vec<String>>,
/// profile list
items: Option<Vec<PrfItem>>,
}
@@ -399,6 +402,11 @@ impl Profiles {
self.chain = chain;
}
/// just change the `field`
pub fn put_valid(&mut self, valid: Option<Vec<String>>) {
self.valid = valid;
}
/// find the item by the uid
pub fn get_item(&self, uid: &String) -> Result<&PrfItem> {
if self.items.is_some() {
@@ -599,9 +607,12 @@ impl Profiles {
None => vec![],
};
let valid = self.valid.clone().unwrap_or(vec![]);
Ok(PrfEnhanced {
current,
chain,
valid,
callback,
})
}
@@ -613,6 +624,8 @@ pub struct PrfEnhanced {
pub chain: Vec<PrfData>,
pub valid: Vec<String>,
pub callback: String,
}

View File

@@ -119,6 +119,7 @@ fn main() -> std::io::Result<()> {
cmds::sync_profiles,
cmds::enhance_profiles,
cmds::change_profile_chain,
cmds::change_profile_valid,
cmds::read_profile_file,
cmds::save_profile_file
]);