feat: profile enhanced mode

This commit is contained in:
GyDi
2022-03-06 14:59:25 +08:00
parent 08dd73fd72
commit 4707e2b02a
10 changed files with 292 additions and 63 deletions

View File

@@ -8,7 +8,7 @@ use crate::{
use anyhow::Result;
use serde_yaml::Mapping;
use std::{path::PathBuf, process::Command};
use tauri::{api, State};
use tauri::{api, Manager, State};
/// get all profiles from `profiles.yaml`
#[tauri::command]
@@ -100,6 +100,43 @@ pub fn select_profile(
wrap_err!(clash.activate(&profiles))
}
/// change the profile chain
#[tauri::command]
pub fn change_profile_chain(
chain: Option<Vec<String>>,
app_handle: tauri::AppHandle,
clash_state: State<'_, ClashState>,
profiles_state: State<'_, ProfilesState>,
) -> Result<(), String> {
let clash = clash_state.0.lock().unwrap();
let mut profiles = profiles_state.0.lock().unwrap();
profiles.put_chain(chain);
app_handle
.get_window("main")
.map(|win| wrap_err!(clash.activate_enhanced(&profiles, win, false)));
Ok(())
}
/// manually exec enhanced profile
#[tauri::command]
pub fn enhance_profiles(
app_handle: tauri::AppHandle,
clash_state: State<'_, ClashState>,
profiles_state: State<'_, ProfilesState>,
) -> Result<(), String> {
let clash = clash_state.0.lock().unwrap();
let profiles = profiles_state.0.lock().unwrap();
app_handle
.get_window("main")
.map(|win| wrap_err!(clash.activate_enhanced(&profiles, win, false)));
Ok(())
}
/// delete profile item
#[tauri::command]
pub fn delete_profile(