- Added `set_public_dns` and `restore_public_dns` functions in `dns.rs` to manage system DNS settings. - Introduced `resolve` module to encapsulate DNS and scheme resolution functionalities. - Implemented `resolve_scheme` function in `scheme.rs` to handle deep links and profile imports. - Created UI readiness management in `ui.rs` to track and update UI loading states. - Developed window management logic in `window.rs` to handle window creation and visibility. - Added initial loading overlay script in `window_script.rs` for better user experience during startup. - Updated server handling in `server.rs` to integrate new resolve functionalities. - Refactored window creation calls in `window_manager.rs` to use the new window management logic.
187 lines
4.9 KiB
Rust
187 lines
4.9 KiB
Rust
use crate::{
|
|
config::Config,
|
|
core::{hotkey::Hotkey, sysopt, tray::Tray, CoreManager, Timer},
|
|
logging, logging_error,
|
|
module::lightweight::auto_lightweight_mode_init,
|
|
process::AsyncHandler,
|
|
utils::{init, logging::Type, resolve::window::create_window, server},
|
|
};
|
|
|
|
pub mod dns;
|
|
pub mod scheme;
|
|
pub mod ui;
|
|
pub mod window;
|
|
pub mod window_script;
|
|
|
|
pub async fn resolve_setup_async() {
|
|
let start_time = std::time::Instant::now();
|
|
logging!(
|
|
info,
|
|
Type::Setup,
|
|
true,
|
|
"开始执行异步设置任务... 线程ID: {:?}",
|
|
std::thread::current().id()
|
|
);
|
|
|
|
AsyncHandler::spawn_blocking(|| async {
|
|
init_scheme();
|
|
init_startup_script().await;
|
|
init_embed_server();
|
|
});
|
|
|
|
AsyncHandler::spawn_blocking(|| async {
|
|
init_config().await;
|
|
init_core_manager().await;
|
|
init_tray().await;
|
|
});
|
|
|
|
AsyncHandler::spawn_blocking(|| async {
|
|
init_system_proxy().await;
|
|
init_system_proxy_guard().await;
|
|
});
|
|
|
|
AsyncHandler::spawn_blocking(|| async {
|
|
init_timer().await;
|
|
init_auto_lightweight_mode().await;
|
|
});
|
|
|
|
AsyncHandler::spawn_blocking(|| async {
|
|
init_hotkey().await;
|
|
init_window().await;
|
|
refresh_tray_menu().await;
|
|
});
|
|
|
|
let elapsed = start_time.elapsed();
|
|
logging!(
|
|
info,
|
|
Type::Setup,
|
|
true,
|
|
"异步设置任务完成,耗时: {:?}",
|
|
elapsed
|
|
);
|
|
|
|
// 如果初始化时间过长,记录警告
|
|
if elapsed.as_secs() > 10 {
|
|
logging!(
|
|
warn,
|
|
Type::Setup,
|
|
true,
|
|
"异步设置任务耗时较长({:?})",
|
|
elapsed
|
|
);
|
|
}
|
|
}
|
|
|
|
pub async fn resolve_reset_async() {
|
|
logging!(info, Type::Tray, true, "Resetting system proxy");
|
|
logging_error!(
|
|
Type::System,
|
|
true,
|
|
sysopt::Sysopt::global().reset_sysproxy().await
|
|
);
|
|
|
|
logging!(info, Type::Core, true, "Stopping core service");
|
|
logging_error!(Type::Core, true, CoreManager::global().stop_core().await);
|
|
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
use dns::restore_public_dns;
|
|
|
|
logging!(info, Type::System, true, "Restoring system DNS settings");
|
|
restore_public_dns().await;
|
|
}
|
|
todo!()
|
|
}
|
|
|
|
pub(super) fn init_scheme() {
|
|
logging!(info, Type::Setup, true, "Initializing custom URL scheme");
|
|
logging_error!(Type::Setup, true, init::init_scheme());
|
|
}
|
|
|
|
pub(super) fn init_embed_server() {
|
|
logging!(info, Type::Setup, true, "Initializing embedded server...");
|
|
server::embed_server();
|
|
}
|
|
|
|
pub(super) async fn init_startup_script() {
|
|
logging!(info, Type::Setup, true, "Initializing startup script");
|
|
logging_error!(Type::Setup, true, init::startup_script().await);
|
|
}
|
|
|
|
pub(super) async fn init_timer() {
|
|
logging!(info, Type::Setup, true, "Initializing timer...");
|
|
logging_error!(Type::Setup, true, Timer::global().init().await);
|
|
}
|
|
|
|
pub(super) async fn init_hotkey() {
|
|
logging!(info, Type::Setup, true, "Initializing hotkey...");
|
|
logging_error!(Type::Setup, true, Hotkey::global().init().await);
|
|
}
|
|
|
|
pub(super) async fn init_auto_lightweight_mode() {
|
|
logging!(
|
|
info,
|
|
Type::Setup,
|
|
true,
|
|
"Initializing auto lightweight mode..."
|
|
);
|
|
logging_error!(Type::Setup, true, auto_lightweight_mode_init().await);
|
|
}
|
|
|
|
pub(super) async fn init_tray() {
|
|
logging!(info, Type::Setup, true, "Initializing system tray...");
|
|
logging_error!(Type::Setup, true, Tray::global().init().await);
|
|
}
|
|
|
|
pub(super) async fn init_config() {
|
|
logging!(info, Type::Setup, true, "Initializing configuration...");
|
|
logging_error!(Type::Setup, true, Config::init_config().await);
|
|
}
|
|
|
|
pub(super) async fn init_core_manager() {
|
|
logging!(info, Type::Setup, true, "Initializing core manager...");
|
|
logging_error!(Type::Setup, true, CoreManager::global().init().await);
|
|
}
|
|
|
|
pub(super) async fn init_system_proxy() {
|
|
logging!(info, Type::Setup, true, "Initializing system proxy...");
|
|
logging_error!(
|
|
Type::Setup,
|
|
true,
|
|
sysopt::Sysopt::global().update_sysproxy().await
|
|
);
|
|
}
|
|
|
|
pub(super) async fn init_system_proxy_guard() {
|
|
logging!(
|
|
info,
|
|
Type::Setup,
|
|
true,
|
|
"Initializing system proxy guard..."
|
|
);
|
|
logging_error!(
|
|
Type::Setup,
|
|
true,
|
|
sysopt::Sysopt::global().init_guard_sysproxy()
|
|
);
|
|
}
|
|
|
|
pub(super) async fn refresh_tray_menu() {
|
|
logging!(info, Type::Setup, true, "Refreshing tray menu...");
|
|
logging_error!(Type::Setup, true, Tray::global().update_part().await);
|
|
}
|
|
|
|
pub(super) async fn init_window() {
|
|
let is_silent_start =
|
|
{ Config::verge().await.latest_ref().enable_silent_start }.unwrap_or(false);
|
|
#[cfg(target_os = "macos")]
|
|
{
|
|
if is_silent_start {
|
|
use crate::core::handle::Handle;
|
|
|
|
Handle::global().set_activation_policy_accessory();
|
|
}
|
|
}
|
|
create_window(!is_silent_start).await;
|
|
}
|