2022-01-07 18:29:20 +03:00
|
|
|
use super::{init, server};
|
2022-01-07 20:27:25 +03:00
|
|
|
use crate::{core::ProfilesConfig, states};
|
2021-12-26 21:29:28 +03:00
|
|
|
use tauri::{App, AppHandle, Manager};
|
2022-01-08 17:23:48 +03:00
|
|
|
use tauri_plugin_shadows::Shadows;
|
2021-12-26 21:29:28 +03:00
|
|
|
|
|
|
|
/// handle something when start app
|
|
|
|
pub fn resolve_setup(app: &App) {
|
2022-01-08 17:23:48 +03:00
|
|
|
// set shadow when window decorations
|
|
|
|
let window = app.get_window("main").unwrap();
|
|
|
|
window.set_shadow(true);
|
|
|
|
|
2022-01-15 16:55:05 +03:00
|
|
|
// enable system blur
|
2022-01-11 21:27:29 +03:00
|
|
|
use tauri_plugin_vibrancy::Vibrancy;
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
window.apply_blur();
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
{
|
|
|
|
use tauri_plugin_vibrancy::MacOSVibrancy;
|
|
|
|
window.apply_vibrancy(MacOSVibrancy::AppearanceBased);
|
|
|
|
}
|
|
|
|
|
2021-12-26 21:29:28 +03:00
|
|
|
// 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());
|
2022-01-15 16:55:05 +03:00
|
|
|
verge.init_launch(app.package_info());
|
|
|
|
if let Err(err) = verge.sync_launch() {
|
2022-01-10 21:24:43 +03:00
|
|
|
log::error!("{}", err);
|
|
|
|
}
|
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>();
|
2022-01-08 17:23:48 +03:00
|
|
|
let mut verge = verge_state.0.lock().unwrap();
|
2022-01-07 18:29:20 +03:00
|
|
|
|
2022-01-08 17:23:48 +03:00
|
|
|
verge.reset_sysproxy();
|
2021-12-26 21:29:28 +03:00
|
|
|
}
|