fix: enhance startup speed and fix connection issues during initialization

This commit is contained in:
Tunglies
2025-09-02 23:10:02 +08:00
parent b51797e238
commit 0bb9cb5097
5 changed files with 25 additions and 29 deletions

View File

@@ -331,8 +331,9 @@ pub fn run() {
logging!(info, Type::Setup, true, "执行主要设置操作...");
resolve::resolve_setup_handle(app_handle);
resolve::resolve_setup_async();
resolve::resolve_setup_sync(app_handle);
resolve::resolve_setup_sync();
logging!(info, Type::Setup, true, "初始化完成,继续执行");
Ok(())

View File

@@ -90,12 +90,6 @@ pub async fn auto_lightweight_mode_init() -> Result<()> {
);
set_lightweight_mode(true).await;
enable_auto_light_weight_mode().await;
// 确保托盘状态更新
if let Err(e) = Tray::global().update_part().await {
log::warn!("Failed to update tray: {e}");
return Err(e);
}
}
Ok(())

View File

@@ -405,14 +405,6 @@ pub async fn init_resources() -> Result<()> {
for file in file_list.iter() {
let src_path = res_dir.join(file);
let dest_path = app_dir.join(file);
logging!(
debug,
Type::Setup,
true,
"src_path: {:?}, dest_path: {:?}",
src_path,
dest_path
);
let handle_copy = |src: PathBuf, dest: PathBuf, file: String| async move {
match fs::copy(&src, &dest).await {

View File

@@ -16,11 +16,16 @@ pub mod ui;
pub mod window;
pub mod window_script;
pub fn resolve_setup_sync(app_handle: AppHandle) {
pub fn resolve_setup_handle(app_handle: AppHandle) {
init_handle(app_handle);
init_scheme();
init_embed_server();
NetworkManager::new().init();
}
pub fn resolve_setup_sync() {
AsyncHandler::spawn(|| async {
AsyncHandler::spawn_blocking(|| init_scheme());
AsyncHandler::spawn_blocking(|| init_embed_server());
AsyncHandler::spawn_blocking(|| NetworkManager::new().init());
});
}
pub fn resolve_setup_async() {
@@ -33,28 +38,30 @@ pub fn resolve_setup_async() {
std::thread::current().id()
);
// AsyncHandler::spawn_blocking(|| AsyncHandler::block_on(init_work_config()));
AsyncHandler::spawn(|| async {
init_work_config().await;
init_resources().await;
init_startup_script().await;
futures::join!(
init_work_config(),
init_resources(),
init_startup_script(),
init_hotkey(),
);
init_timer().await;
init_hotkey().await;
init_auto_lightweight_mode().await;
init_verge_config().await;
init_core_manager().await;
init_system_proxy().await;
init_system_proxy().await;
AsyncHandler::spawn_blocking(|| {
init_system_proxy_guard();
});
init_window().await;
init_tray().await;
refresh_tray_menu().await
let tray_and_refresh = async {
init_tray().await;
refresh_tray_menu().await;
};
futures::join!(init_window(), tray_and_refresh,);
});
let elapsed = start_time.elapsed();