Files
clash-proxy/src-tauri/src/utils/resolve.rs

70 lines
1.6 KiB
Rust
Raw Normal View History

2022-04-15 01:29:25 +08:00
use crate::log_if_err;
2022-04-19 01:41:20 +08:00
use crate::{core::Core, utils::init, utils::server};
2021-12-27 02:29:28 +08: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 23:29:20 +08:00
// init states
2022-04-19 01:41:20 +08:00
let core = app.state::<Core>();
2021-12-27 02:29:28 +08:00
2022-04-19 01:41:20 +08:00
core.set_win(app.get_window("main"));
core.init();
2021-12-27 02:29:28 +08:00
2022-04-19 01:41:20 +08:00
// clash.set_window(app.get_window("main"));
// log_if_err!(clash.run_sidecar(&profiles, true));
2022-01-05 23:30:18 +08:00
2022-04-19 01:41:20 +08:00
resolve_window(app, None);
2021-12-27 02:29:28 +08:00
}
/// reset system proxy
pub fn resolve_reset(app_handle: &AppHandle) {
2022-04-19 01:41:20 +08:00
let core = app_handle.state::<Core>();
let mut verge = core.verge.lock().unwrap();
2022-01-07 23:29:20 +08:00
2022-01-08 22:23:48 +08:00
verge.reset_sysproxy();
2021-12-27 02:29:28 +08:00
}
2022-02-20 23:46:13 +08:00
/// customize the window theme
2022-03-26 18:56:16 +08:00
fn resolve_window(app: &App, hide: Option<bool>) {
2022-02-20 23:46:13 +08:00
let window = app.get_window("main").unwrap();
2022-03-26 18:56:16 +08:00
// silent start
hide.map(|hide| {
if hide {
window.hide().unwrap();
}
});
2022-02-20 23:46:13 +08:00
#[cfg(target_os = "windows")]
{
2022-03-03 20:37:06 +08:00
use window_shadows::set_shadow;
use window_vibrancy::apply_blur;
2022-02-20 23:46:13 +08:00
window.set_decorations(false).unwrap();
2022-03-03 20:37:06 +08:00
set_shadow(&window, true).unwrap();
2022-03-08 10:44:41 +08:00
apply_blur(&window, None).unwrap();
2022-02-20 23:46:13 +08:00
}
#[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);
}
}