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
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> {
DownloadManagerState build();

View File

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

View File

@ -37,10 +37,15 @@ static TASK_OUTPUT_FOLDERS: once_cell::sync::Lazy<RwLock<HashMap<usize, String>>
/// Download task status
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum DownloadTaskStatus {
Initializing,
/// Checking/verifying existing files
Checking,
/// Actively downloading
Live,
/// Paused
Paused,
/// Error occurred
Error,
/// Download completed
Finished,
}
@ -368,9 +373,11 @@ pub async fn downloader_get_task_info(task_id: usize) -> Result<DownloadTaskInfo
};
// 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 down = (live.download_speed.mbps * 1024.0 * 1024.0 / 8.0) as u64;
let up = (live.upload_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) as u64;
let peers = (live.snapshot.peer_stats.queued + live.snapshot.peer_stats.connecting + live.snapshot.peer_stats.live) as usize;
(down, up, peers)
} else {
@ -405,7 +412,7 @@ fn get_task_status(stats: &TorrentStats) -> DownloadTaskStatus {
}
match stats.state {
TorrentStatsState::Initializing => DownloadTaskStatus::Initializing,
TorrentStatsState::Initializing => DownloadTaskStatus::Checking,
TorrentStatsState::Live => DownloadTaskStatus::Live,
TorrentStatsState::Paused => DownloadTaskStatus::Paused,
TorrentStatsState::Error => DownloadTaskStatus::Error,
@ -485,7 +492,7 @@ pub async fn downloader_get_global_stats() -> Result<DownloadGlobalStat> {
match task.status {
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
fn cst_decode(self) -> crate::api::downloader_api::DownloadTaskStatus {
match self {
0 => crate::api::downloader_api::DownloadTaskStatus::Initializing,
0 => crate::api::downloader_api::DownloadTaskStatus::Checking,
1 => crate::api::downloader_api::DownloadTaskStatus::Live,
2 => crate::api::downloader_api::DownloadTaskStatus::Paused,
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 {
let mut inner = <i32>::sse_decode(deserializer);
return match inner {
0 => crate::api::downloader_api::DownloadTaskStatus::Initializing,
0 => crate::api::downloader_api::DownloadTaskStatus::Checking,
1 => crate::api::downloader_api::DownloadTaskStatus::Live,
2 => crate::api::downloader_api::DownloadTaskStatus::Paused,
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 {
fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi {
match self {
Self::Initializing => 0.into_dart(),
Self::Checking => 0.into_dart(),
Self::Live => 1.into_dart(),
Self::Paused => 2.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) {
<i32>::sse_encode(
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::Paused => 2,
crate::api::downloader_api::DownloadTaskStatus::Error => 3,