添加后端内部轮询

This commit is contained in:
柚子
2025-03-04 16:44:50 +08:00
parent 919a62ee60
commit 400880cc3e
2 changed files with 57 additions and 1 deletions

View File

@@ -40,6 +40,23 @@ pub fn run() {
}
_ => {}
})
.setup(|app| {
let app_handle = app.handle().clone();
// 创建后台任务检查下载状态
tauri::async_runtime::spawn(async move {
loop {
{
let download_manager = app_handle.state::<DownloadManager>();
if download_manager.has_downloads() {
let _ = download_manager.get_downloads().await;
}
}
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
}
});
Ok(())
})
.run(tauri::generate_context!())
.expect("error while running tauri application");
}