refactor: fix startup init chain — resolve_done semantics, dedupe events, cleanup

Backend:
- Move resolve_done() from sync setup() to async task after futures::join!
  so Timer waits for actual init completion instead of firing immediately
- Replace std::thread::sleep(50ms) with tokio::time::sleep in async context
- Remove duplicate refresh_tray_menu in tray_init (keep post-join call only)
- Delete dead code reset_resolve_done (process restarts, static is destroyed)
- Rename create_window(is_show) → create_window(should_create) for clarity

Frontend:
- Remove duplicate verge://refresh-clash-config listener from AppDataProvider
  (useLayoutEvents handles it via invalidateQueries — single consumer path)
- Stabilize useEffect deps with useRef for TQ refetch references
- Simplify AppDataProvider event listener setup (profile-changed + proxy only)
This commit is contained in:
Tunglies
2026-04-06 12:20:16 +08:00
parent 437fef1c30
commit 3aa39bff94
5 changed files with 29 additions and 128 deletions
+2 -10
View File
@@ -62,14 +62,9 @@ pub fn resolve_setup_async() {
init_system_proxy_guard().await;
});
let tray_init = async {
init_tray().await;
refresh_tray_menu().await;
};
let _ = futures::join!(
core_init,
tray_init,
init_tray(),
init_timer(),
init_hotkey(),
init_auto_lightweight_boot(),
@@ -79,6 +74,7 @@ pub fn resolve_setup_async() {
Handle::refresh_clash();
refresh_tray_menu().await;
resolve_done();
});
}
@@ -220,7 +216,3 @@ pub fn resolve_done() {
pub fn is_resolve_done() -> bool {
RESOLVE_DONE.load(Ordering::Acquire)
}
pub fn reset_resolve_done() {
RESOLVE_DONE.store(false, Ordering::Release);
}
+4 -4
View File
@@ -129,7 +129,7 @@ impl WindowManager {
logging!(info, Type::Window, "窗口不存在,创建新窗口");
if Self::create_window(true).await {
logging!(info, Type::Window, "窗口创建成功");
std::thread::sleep(std::time::Duration::from_millis(50));
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
WindowOperationResult::Created
} else {
logging!(warn, Type::Window, "窗口创建失败");
@@ -286,11 +286,11 @@ impl WindowManager {
/// 创建新窗口,防抖避免重复调用
/// 窗口创建后保持隐藏,由前端 index.html 在 overlay 渲染后调用 show,避免主题闪烁
pub fn create_window(is_show: bool) -> Pin<Box<dyn Future<Output = bool> + Send>> {
pub fn create_window(should_create: bool) -> Pin<Box<dyn Future<Output = bool> + Send>> {
Box::pin(async move {
logging!(info, Type::Window, "开始创建/显示主窗口, is_show={}", is_show);
logging!(info, Type::Window, "开始创建主窗口, should_create={}", should_create);
if !is_show {
if !should_create {
return false;
}