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

78 lines
1.9 KiB
Rust
Raw Normal View History

2022-01-07 18:29:20 +03:00
use super::{init, server};
use crate::{core::Profiles, 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) {
2022-02-20 18:46:13 +03:00
resolve_window(app);
2022-01-11 21:27:29 +03:00
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 = Profiles::read_file();
2022-01-20 21:31:44 +03:00
if let Err(err) = profiles.activate(&clash) {
2022-01-07 18:29:20 +03:00
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-02-21 17:33:37 +03:00
verge.init_launch();
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
}
2022-02-20 18:46:13 +03:00
/// customize the window theme
fn resolve_window(app: &App) {
let window = app.get_window("main").unwrap();
#[cfg(target_os = "windows")]
{
use tauri_plugin_shadows::Shadows;
use tauri_plugin_vibrancy::Vibrancy;
window.set_decorations(false).unwrap();
window.set_shadow(true);
window.apply_blur();
}
#[cfg(target_os = "macos")]
{
use tauri::LogicalSize;
use tauri::Size::Logical;
window.set_decorations(true).unwrap();
window
.set_size(Logical(LogicalSize {
width: 800.0,
height: 610.0,
}))
.unwrap();
// use tauri_plugin_vibrancy::MacOSVibrancy;
// #[allow(deprecated)]
// window.apply_vibrancy(MacOSVibrancy::AppearanceBased);
}
}