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

64 lines
1.4 KiB
Rust
Raw Normal View History

2022-04-18 20:41:20 +03:00
use crate::{core::Core, utils::init, utils::server};
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
2022-04-18 20:41:20 +03:00
let core = app.state::<Core>();
2021-12-26 21:29:28 +03:00
2022-04-18 20:41:20 +03:00
core.set_win(app.get_window("main"));
2022-04-19 09:38:59 +03:00
core.init(app.app_handle());
2021-12-26 21:29:28 +03:00
2022-04-19 09:38:59 +03:00
resolve_window(app);
2021-12-26 21:29:28 +03:00
}
/// reset system proxy
pub fn resolve_reset(app_handle: &AppHandle) {
2022-04-18 20:41:20 +03:00
let core = app_handle.state::<Core>();
2022-04-19 20:44:47 +03:00
let mut sysopt = core.sysopt.lock();
sysopt.reset_sysproxy();
2022-04-25 15:00:11 +03:00
drop(sysopt);
let mut service = core.service.lock();
crate::log_if_err!(service.stop());
2021-12-26 21:29:28 +03:00
}
2022-02-20 18:46:13 +03:00
/// customize the window theme
2022-04-19 09:38:59 +03:00
fn resolve_window(app: &App) {
2022-02-20 18:46:13 +03:00
let window = app.get_window("main").unwrap();
#[cfg(target_os = "windows")]
{
2022-05-09 09:41:26 +03:00
use crate::utils::winhelp;
2022-03-03 15:37:06 +03:00
use window_shadows::set_shadow;
use window_vibrancy::apply_blur;
2022-02-20 18:46:13 +03:00
2022-05-09 09:01:14 +03:00
let _ = window.set_decorations(false);
let _ = set_shadow(&window, true);
2022-05-09 09:41:26 +03:00
// todo
// win11 disable this feature temporarily due to lag
if !winhelp::is_win11() {
let _ = apply_blur(&window, None);
}
2022-02-20 18:46:13 +03:00
}
#[cfg(target_os = "macos")]
{
use tauri::LogicalSize;
use tauri::Size::Logical;
2022-05-09 09:01:14 +03:00
let _ = window.set_decorations(true);
let _ = window.set_size(Logical(LogicalSize {
width: 800.0,
height: 620.0,
}));
2022-02-20 18:46:13 +03:00
}
}