refactor: streamline asynchronous handling in config and resolve setup
This commit is contained in:
@@ -123,10 +123,8 @@ impl Config {
|
||||
|
||||
// 在单独的任务中发送通知
|
||||
if let Some((msg_type, msg_content)) = validation_result {
|
||||
AsyncHandler::spawn(move || async move {
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
handle::Handle::notice_message(msg_type, &msg_content);
|
||||
});
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
handle::Handle::notice_message(msg_type, &msg_content);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
@@ -133,23 +133,21 @@ mod app_init {
|
||||
}
|
||||
|
||||
/// Initialize core components asynchronously
|
||||
pub fn init_core_async() {
|
||||
AsyncHandler::spawn(move || async move {
|
||||
logging!(info, Type::Setup, true, "异步执行应用设置...");
|
||||
match timeout(Duration::from_secs(30), resolve::resolve_setup_async()).await {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Setup, true, "应用设置成功完成");
|
||||
}
|
||||
Err(_) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Setup,
|
||||
true,
|
||||
"应用设置超时(30秒),继续执行后续流程"
|
||||
);
|
||||
}
|
||||
pub async fn init_core_async() {
|
||||
logging!(info, Type::Setup, true, "异步执行应用设置...");
|
||||
match timeout(Duration::from_secs(30), resolve::resolve_setup_async()).await {
|
||||
Ok(_) => {
|
||||
logging!(info, Type::Setup, true, "应用设置成功完成");
|
||||
}
|
||||
});
|
||||
Err(_) => {
|
||||
logging!(
|
||||
error,
|
||||
Type::Setup,
|
||||
true,
|
||||
"应用设置超时(30秒),继续执行后续流程"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Initialize core components synchronously
|
||||
@@ -365,12 +363,14 @@ pub fn run() {
|
||||
let app_handle = app.handle().clone();
|
||||
|
||||
// Initialize core components asynchronously
|
||||
app_init::init_core_async();
|
||||
AsyncHandler::spawn_blocking(move || async move {
|
||||
app_init::init_core_async().await;
|
||||
});
|
||||
|
||||
logging!(info, Type::Setup, true, "执行主要设置操作...");
|
||||
|
||||
// Initialize core components synchronously
|
||||
AsyncHandler::spawn(move || async move {
|
||||
AsyncHandler::spawn_blocking(move || async move {
|
||||
if let Err(e) = app_init::init_core_sync(&app_handle).await {
|
||||
logging!(
|
||||
error,
|
||||
|
||||
@@ -51,7 +51,11 @@ impl AsyncHandler {
|
||||
F: ?Sized,
|
||||
{
|
||||
const TRACE_MINI_SIZE: usize = 4;
|
||||
const TRACE_SPECIAL_SIZE: usize = 24;
|
||||
let size = std::mem::size_of_val(f);
|
||||
if size == TRACE_SPECIAL_SIZE {
|
||||
return;
|
||||
}
|
||||
if size <= TRACE_MINI_SIZE {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -29,23 +29,17 @@ pub async fn resolve_setup_async() {
|
||||
init_embed_server();
|
||||
});
|
||||
|
||||
AsyncHandler::spawn_blocking(|| async {
|
||||
AsyncHandler::spawn(|| 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;
|
||||
|
||||
Reference in New Issue
Block a user