clash-verge/src-tauri/src/utils/resolve.rs

41 lines
1.1 KiB
Rust
Raw Normal View History

2022-01-07 18:29:20 +03:00
use super::{init, server};
use crate::{config::ProfilesConfig, states};
2021-12-26 21:29:28 +03:00
use tauri::{App, AppHandle, Manager};
/// handle something when start app
pub fn resolve_setup(app: &App) {
// setup a simple http server for singleton
server::embed_server(&app.handle());
// init app config
init::init_app(app.package_info());
2022-01-07 18:29:20 +03:00
// init states
let clash_state = app.state::<states::ClashState>();
let verge_state = app.state::<states::VergeState>();
let profiles_state = app.state::<states::ProfilesState>();
2021-12-26 21:29:28 +03:00
2022-01-07 18:29:20 +03:00
let mut clash = clash_state.0.lock().unwrap();
let mut verge = verge_state.0.lock().unwrap();
let mut profiles = profiles_state.0.lock().unwrap();
2021-12-26 21:29:28 +03:00
2022-01-07 18:29:20 +03:00
if let Err(err) = clash.run_sidecar() {
log::error!("{}", err);
2021-12-26 21:29:28 +03:00
}
2022-01-05 18:30:18 +03:00
*profiles = ProfilesConfig::read_file();
2022-01-07 18:29:20 +03:00
if let Err(err) = profiles.activate(clash.info.clone()) {
log::error!("{}", err);
}
2022-01-05 18:30:18 +03:00
2022-01-07 18:29:20 +03:00
verge.init_sysproxy(clash.info.port.clone());
2021-12-26 21:29:28 +03:00
}
/// reset system proxy
pub fn resolve_reset(app_handle: &AppHandle) {
2022-01-07 18:29:20 +03:00
let verge_state = app_handle.state::<states::VergeState>();
let mut verge_arc = verge_state.0.lock().unwrap();
verge_arc.reset_sysproxy();
2021-12-26 21:29:28 +03:00
}