2021-12-04 14:31:26 +08:00
|
|
|
#![cfg_attr(
|
2022-11-12 11:37:23 +08:00
|
|
|
all(not(debug_assertions), target_os = "windows"),
|
|
|
|
|
windows_subsystem = "windows"
|
2021-12-04 14:31:26 +08:00
|
|
|
)]
|
|
|
|
|
|
2021-12-18 02:01:02 +08:00
|
|
|
mod cmds;
|
2022-08-11 02:55:10 +08:00
|
|
|
mod config;
|
2022-01-08 01:27:25 +08:00
|
|
|
mod core;
|
2022-11-14 01:26:33 +08:00
|
|
|
mod enhance;
|
2022-09-14 01:19:02 +08:00
|
|
|
mod feat;
|
2021-12-14 16:07:15 +08:00
|
|
|
mod utils;
|
2021-12-04 14:31:26 +08:00
|
|
|
|
2024-09-13 03:21:55 +08:00
|
|
|
use crate::utils::{resolve, resolve::resolve_scheme, server};
|
|
|
|
|
use tauri::Listener;
|
2021-12-04 14:31:26 +08:00
|
|
|
|
|
|
|
|
fn main() -> std::io::Result<()> {
|
2022-11-12 11:37:23 +08:00
|
|
|
// 单例检测
|
2024-06-29 19:02:37 +08:00
|
|
|
let app_exists: bool = tauri::async_runtime::block_on(async move {
|
|
|
|
|
if server::check_singleton().await.is_err() {
|
|
|
|
|
println!("app exists");
|
|
|
|
|
true
|
|
|
|
|
} else {
|
|
|
|
|
false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
if app_exists {
|
2022-11-12 11:37:23 +08:00
|
|
|
return Ok(());
|
|
|
|
|
}
|
2022-09-06 00:45:01 +08:00
|
|
|
|
2024-05-03 18:00:55 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
|
|
|
|
|
2024-09-04 08:54:15 +08:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
let devtools = tauri_plugin_devtools::init();
|
2022-10-28 01:02:47 +08:00
|
|
|
|
2022-11-12 11:37:23 +08:00
|
|
|
#[allow(unused_mut)]
|
|
|
|
|
let mut builder = tauri::Builder::default()
|
2024-09-02 19:33:17 +08:00
|
|
|
.plugin(tauri_plugin_updater::Builder::new().build())
|
|
|
|
|
.plugin(tauri_plugin_clipboard_manager::init())
|
|
|
|
|
.plugin(tauri_plugin_process::init())
|
|
|
|
|
.plugin(tauri_plugin_global_shortcut::Builder::new().build())
|
|
|
|
|
.plugin(tauri_plugin_notification::init())
|
|
|
|
|
.plugin(tauri_plugin_fs::init())
|
|
|
|
|
.plugin(tauri_plugin_dialog::init())
|
|
|
|
|
.plugin(tauri_plugin_shell::init())
|
2024-09-13 03:21:55 +08:00
|
|
|
.plugin(tauri_plugin_deep_link::init())
|
2024-01-10 17:36:35 +08:00
|
|
|
.setup(|app| {
|
2024-09-13 03:21:55 +08:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
{
|
|
|
|
|
use tauri_plugin_deep_link::DeepLinkExt;
|
|
|
|
|
app.deep_link().register_all()?;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.listen("deep-link://new-url", |event| {
|
|
|
|
|
tauri::async_runtime::spawn(async move {
|
|
|
|
|
let payload = event.payload();
|
|
|
|
|
log_err!(resolve_scheme(payload.to_string()).await);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-29 19:02:37 +08:00
|
|
|
tauri::async_runtime::block_on(async move {
|
|
|
|
|
resolve::resolve_setup(app).await;
|
|
|
|
|
});
|
2024-09-13 03:21:55 +08:00
|
|
|
|
2024-01-10 17:36:35 +08:00
|
|
|
Ok(())
|
|
|
|
|
})
|
2022-11-12 11:37:23 +08:00
|
|
|
.invoke_handler(tauri::generate_handler![
|
|
|
|
|
// common
|
|
|
|
|
cmds::get_sys_proxy,
|
2024-05-26 17:59:39 +08:00
|
|
|
cmds::get_auto_proxy,
|
2022-11-12 11:37:23 +08:00
|
|
|
cmds::open_app_dir,
|
|
|
|
|
cmds::open_logs_dir,
|
|
|
|
|
cmds::open_web_url,
|
2022-12-13 00:44:24 +08:00
|
|
|
cmds::open_core_dir,
|
2023-12-15 21:39:34 +08:00
|
|
|
cmds::get_portable_flag,
|
2024-07-07 18:02:29 +08:00
|
|
|
cmds::get_network_interfaces,
|
2022-11-14 01:26:33 +08:00
|
|
|
// cmds::kill_sidecar,
|
2022-11-12 11:37:23 +08:00
|
|
|
cmds::restart_sidecar,
|
|
|
|
|
// clash
|
|
|
|
|
cmds::get_clash_info,
|
|
|
|
|
cmds::get_clash_logs,
|
|
|
|
|
cmds::patch_clash_config,
|
|
|
|
|
cmds::change_clash_core,
|
|
|
|
|
cmds::get_runtime_config,
|
|
|
|
|
cmds::get_runtime_yaml,
|
|
|
|
|
cmds::get_runtime_exists,
|
|
|
|
|
cmds::get_runtime_logs,
|
2023-11-22 00:15:41 -08:00
|
|
|
cmds::uwp::invoke_uwp_tool,
|
2024-07-13 01:03:46 +08:00
|
|
|
cmds::copy_clash_env,
|
2022-11-12 11:37:23 +08:00
|
|
|
// verge
|
|
|
|
|
cmds::get_verge_config,
|
|
|
|
|
cmds::patch_verge_config,
|
2024-01-17 11:02:17 +08:00
|
|
|
cmds::test_delay,
|
2024-02-24 11:25:22 +08:00
|
|
|
cmds::get_app_dir,
|
|
|
|
|
cmds::copy_icon_file,
|
2024-03-15 16:42:17 +08:00
|
|
|
cmds::download_icon_cache,
|
2024-03-11 20:19:21 +08:00
|
|
|
cmds::open_devtools,
|
2024-02-02 16:32:19 +08:00
|
|
|
cmds::exit_app,
|
2024-07-13 14:10:50 +08:00
|
|
|
cmds::get_network_interfaces_info,
|
2022-11-14 01:26:33 +08:00
|
|
|
// cmds::update_hotkeys,
|
2022-11-12 11:37:23 +08:00
|
|
|
// profile
|
2022-11-18 18:18:41 +08:00
|
|
|
cmds::get_profiles,
|
|
|
|
|
cmds::enhance_profiles,
|
|
|
|
|
cmds::patch_profiles_config,
|
2022-11-12 11:37:23 +08:00
|
|
|
cmds::view_profile,
|
|
|
|
|
cmds::patch_profile,
|
|
|
|
|
cmds::create_profile,
|
2022-11-14 01:45:58 +08:00
|
|
|
cmds::import_profile,
|
2023-11-29 08:54:02 +08:00
|
|
|
cmds::reorder_profile,
|
2022-11-12 11:37:23 +08:00
|
|
|
cmds::update_profile,
|
|
|
|
|
cmds::delete_profile,
|
|
|
|
|
cmds::read_profile_file,
|
|
|
|
|
cmds::save_profile_file,
|
|
|
|
|
// service mode
|
|
|
|
|
cmds::service::check_service,
|
|
|
|
|
cmds::service::install_service,
|
|
|
|
|
cmds::service::uninstall_service,
|
2023-11-01 20:52:38 +08:00
|
|
|
// clash api
|
|
|
|
|
cmds::clash_api_get_proxy_delay
|
2022-11-12 11:37:23 +08:00
|
|
|
]);
|
2022-07-13 00:54:47 +08:00
|
|
|
|
2024-09-04 08:54:15 +08:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
|
{
|
|
|
|
|
builder = builder.plugin(devtools);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-14 01:26:33 +08:00
|
|
|
let app = builder
|
2022-11-12 11:37:23 +08:00
|
|
|
.build(tauri::generate_context!())
|
|
|
|
|
.expect("error while running tauri application");
|
2022-09-09 16:42:35 +08:00
|
|
|
|
2022-11-12 11:37:23 +08:00
|
|
|
app.run(|app_handle, e| match e {
|
2024-02-02 17:26:31 +08:00
|
|
|
tauri::RunEvent::ExitRequested { api, .. } => {
|
|
|
|
|
api.prevent_exit();
|
|
|
|
|
}
|
2023-07-22 10:58:16 +08:00
|
|
|
tauri::RunEvent::WindowEvent { label, event, .. } => {
|
|
|
|
|
if label == "main" {
|
|
|
|
|
match event {
|
2023-12-12 16:23:39 +08:00
|
|
|
tauri::WindowEvent::Destroyed => {
|
2024-01-10 17:36:35 +08:00
|
|
|
let _ = resolve::save_window_size_position(app_handle, true);
|
2023-12-12 16:23:39 +08:00
|
|
|
}
|
2023-07-22 10:58:16 +08:00
|
|
|
tauri::WindowEvent::CloseRequested { .. } => {
|
2024-01-10 17:36:35 +08:00
|
|
|
let _ = resolve::save_window_size_position(app_handle, true);
|
2023-07-22 13:13:16 +08:00
|
|
|
}
|
|
|
|
|
tauri::WindowEvent::Moved(_) | tauri::WindowEvent::Resized(_) => {
|
2024-01-10 17:36:35 +08:00
|
|
|
let _ = resolve::save_window_size_position(app_handle, false);
|
2023-07-22 10:58:16 +08:00
|
|
|
}
|
|
|
|
|
_ => {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-11-12 11:37:23 +08:00
|
|
|
_ => {}
|
|
|
|
|
});
|
2022-07-13 00:54:47 +08:00
|
|
|
|
2022-11-12 11:37:23 +08:00
|
|
|
Ok(())
|
2021-12-04 14:31:26 +08:00
|
|
|
}
|