fix: download status

This commit is contained in:
xkeyC 2025-12-05 17:40:45 +08:00
parent 39ddea7254
commit 53ffab783f
5 changed files with 36 additions and 14 deletions

View File

@ -234,4 +234,19 @@ class DownloadTaskInfo {
} }
/// Download task status /// Download task status
enum DownloadTaskStatus { initializing, live, paused, error, finished } enum DownloadTaskStatus {
/// Checking/verifying existing files
checking,
/// Actively downloading
live,
/// Paused
paused,
/// Error occurred
error,
/// Download completed
finished,
}

View File

@ -41,7 +41,7 @@ final class DownloadManagerProvider
} }
} }
String _$downloadManagerHash() => r'95a8105bb544c8a1996f321e1d0258c41e18effa'; String _$downloadManagerHash() => r'f12d3fb1d7c03fdfccff7d07903218f38a860437';
abstract class _$DownloadManager extends $Notifier<DownloadManagerState> { abstract class _$DownloadManager extends $Notifier<DownloadManagerState> {
DownloadManagerState build(); DownloadManagerState build();

View File

@ -131,8 +131,8 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
switch (status) { switch (status) {
case DownloadTaskStatus.live: case DownloadTaskStatus.live:
return "live"; return "live";
case DownloadTaskStatus.initializing: case DownloadTaskStatus.checking:
return "initializing"; return "checking";
case DownloadTaskStatus.paused: case DownloadTaskStatus.paused:
return "paused"; return "paused";
case DownloadTaskStatus.error: case DownloadTaskStatus.error:
@ -191,7 +191,7 @@ class HomeDownloaderUIModel extends _$HomeDownloaderUIModel {
case DownloadTaskStatus.live: case DownloadTaskStatus.live:
activeTasks.add(task); activeTasks.add(task);
break; break;
case DownloadTaskStatus.initializing: case DownloadTaskStatus.checking:
case DownloadTaskStatus.paused: case DownloadTaskStatus.paused:
waitingTasks.add(task); waitingTasks.add(task);
break; break;

View File

@ -37,10 +37,15 @@ static TASK_OUTPUT_FOLDERS: once_cell::sync::Lazy<RwLock<HashMap<usize, String>>
/// Download task status /// Download task status
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DownloadTaskStatus { pub enum DownloadTaskStatus {
Initializing, /// Checking/verifying existing files
Checking,
/// Actively downloading
Live, Live,
/// Paused
Paused, Paused,
/// Error occurred
Error, Error,
/// Download completed
Finished, Finished,
} }
@ -368,9 +373,11 @@ pub async fn downloader_get_task_info(task_id: usize) -> Result<DownloadTaskInfo
}; };
// Get speed from live stats // Get speed from live stats
// Note: mbps in rqbit is actually MiB/s (bytes_per_second / 1024 / 1024)
// So we convert back to bytes per second: mbps * 1024 * 1024
let (download_speed, upload_speed, num_peers) = if let Some(live) = &stats.live { let (download_speed, upload_speed, num_peers) = if let Some(live) = &stats.live {
let down = (live.download_speed.mbps * 1024.0 * 1024.0 / 8.0) as u64; let down = (live.download_speed.mbps * 1024.0 * 1024.0) as u64;
let up = (live.upload_speed.mbps * 1024.0 * 1024.0 / 8.0) as u64; let up = (live.upload_speed.mbps * 1024.0 * 1024.0) as u64;
let peers = (live.snapshot.peer_stats.queued + live.snapshot.peer_stats.connecting + live.snapshot.peer_stats.live) as usize; let peers = (live.snapshot.peer_stats.queued + live.snapshot.peer_stats.connecting + live.snapshot.peer_stats.live) as usize;
(down, up, peers) (down, up, peers)
} else { } else {
@ -405,7 +412,7 @@ fn get_task_status(stats: &TorrentStats) -> DownloadTaskStatus {
} }
match stats.state { match stats.state {
TorrentStatsState::Initializing => DownloadTaskStatus::Initializing, TorrentStatsState::Initializing => DownloadTaskStatus::Checking,
TorrentStatsState::Live => DownloadTaskStatus::Live, TorrentStatsState::Live => DownloadTaskStatus::Live,
TorrentStatsState::Paused => DownloadTaskStatus::Paused, TorrentStatsState::Paused => DownloadTaskStatus::Paused,
TorrentStatsState::Error => DownloadTaskStatus::Error, TorrentStatsState::Error => DownloadTaskStatus::Error,
@ -485,7 +492,7 @@ pub async fn downloader_get_global_stats() -> Result<DownloadGlobalStat> {
match task.status { match task.status {
DownloadTaskStatus::Live => stat.num_active += 1, DownloadTaskStatus::Live => stat.num_active += 1,
DownloadTaskStatus::Paused | DownloadTaskStatus::Initializing => stat.num_waiting += 1, DownloadTaskStatus::Paused | DownloadTaskStatus::Checking => stat.num_waiting += 1,
_ => {} _ => {}
} }
} }

View File

@ -1879,7 +1879,7 @@ impl CstDecode<crate::api::downloader_api::DownloadTaskStatus> for i32 {
// Codec=Cst (C-struct based), see doc to use other codecs // Codec=Cst (C-struct based), see doc to use other codecs
fn cst_decode(self) -> crate::api::downloader_api::DownloadTaskStatus { fn cst_decode(self) -> crate::api::downloader_api::DownloadTaskStatus {
match self { match self {
0 => crate::api::downloader_api::DownloadTaskStatus::Initializing, 0 => crate::api::downloader_api::DownloadTaskStatus::Checking,
1 => crate::api::downloader_api::DownloadTaskStatus::Live, 1 => crate::api::downloader_api::DownloadTaskStatus::Live,
2 => crate::api::downloader_api::DownloadTaskStatus::Paused, 2 => crate::api::downloader_api::DownloadTaskStatus::Paused,
3 => crate::api::downloader_api::DownloadTaskStatus::Error, 3 => crate::api::downloader_api::DownloadTaskStatus::Error,
@ -2074,7 +2074,7 @@ impl SseDecode for crate::api::downloader_api::DownloadTaskStatus {
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
let mut inner = <i32>::sse_decode(deserializer); let mut inner = <i32>::sse_decode(deserializer);
return match inner { return match inner {
0 => crate::api::downloader_api::DownloadTaskStatus::Initializing, 0 => crate::api::downloader_api::DownloadTaskStatus::Checking,
1 => crate::api::downloader_api::DownloadTaskStatus::Live, 1 => crate::api::downloader_api::DownloadTaskStatus::Live,
2 => crate::api::downloader_api::DownloadTaskStatus::Paused, 2 => crate::api::downloader_api::DownloadTaskStatus::Paused,
3 => crate::api::downloader_api::DownloadTaskStatus::Error, 3 => crate::api::downloader_api::DownloadTaskStatus::Error,
@ -2635,7 +2635,7 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::downloader_api::DownloadTaskI
impl flutter_rust_bridge::IntoDart for crate::api::downloader_api::DownloadTaskStatus { impl flutter_rust_bridge::IntoDart for crate::api::downloader_api::DownloadTaskStatus {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self { match self {
Self::Initializing => 0.into_dart(), Self::Checking => 0.into_dart(),
Self::Live => 1.into_dart(), Self::Live => 1.into_dart(),
Self::Paused => 2.into_dart(), Self::Paused => 2.into_dart(),
Self::Error => 3.into_dart(), Self::Error => 3.into_dart(),
@ -3029,7 +3029,7 @@ impl SseEncode for crate::api::downloader_api::DownloadTaskStatus {
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
<i32>::sse_encode( <i32>::sse_encode(
match self { match self {
crate::api::downloader_api::DownloadTaskStatus::Initializing => 0, crate::api::downloader_api::DownloadTaskStatus::Checking => 0,
crate::api::downloader_api::DownloadTaskStatus::Live => 1, crate::api::downloader_api::DownloadTaskStatus::Live => 1,
crate::api::downloader_api::DownloadTaskStatus::Paused => 2, crate::api::downloader_api::DownloadTaskStatus::Paused => 2,
crate::api::downloader_api::DownloadTaskStatus::Error => 3, crate::api::downloader_api::DownloadTaskStatus::Error => 3,