fix(backend): detect torrent completion by percent_complete reaching 100%

- Changed detection from status change to percent_complete threshold
- Added logging for status changes (debugging)
- More reliable completion detection
This commit is contained in:
spinline
2026-02-05 22:05:14 +03:00
parent b1c7ff856e
commit 480604a97a

View File

@@ -1,4 +1,4 @@
use shared::{AppEvent, NotificationLevel, SystemNotification, Torrent, TorrentStatus, TorrentUpdate}; use shared::{AppEvent, NotificationLevel, SystemNotification, Torrent, TorrentUpdate};
#[derive(Debug)] #[derive(Debug)]
pub enum DiffResult { pub enum DiffResult {
@@ -62,6 +62,15 @@ pub fn diff_torrents(old: &[Torrent], new: &[Torrent]) -> DiffResult {
if (old_t.percent_complete - new_t.percent_complete).abs() > 0.01 { if (old_t.percent_complete - new_t.percent_complete).abs() > 0.01 {
update.percent_complete = Some(new_t.percent_complete); update.percent_complete = Some(new_t.percent_complete);
has_changes = true; has_changes = true;
// Check for torrent completion: reached 100%
if old_t.percent_complete < 100.0 && new_t.percent_complete >= 100.0 {
tracing::info!("Torrent completed: {} ({})", new_t.name, new_t.hash);
events.push(AppEvent::Notification(SystemNotification {
level: NotificationLevel::Success,
message: format!("Torrent tamamlandı: {}", new_t.name),
}));
}
} }
if old_t.completed != new_t.completed { if old_t.completed != new_t.completed {
update.completed = Some(new_t.completed); update.completed = Some(new_t.completed);
@@ -75,13 +84,11 @@ pub fn diff_torrents(old: &[Torrent], new: &[Torrent]) -> DiffResult {
update.status = Some(new_t.status.clone()); update.status = Some(new_t.status.clone());
has_changes = true; has_changes = true;
// Check for torrent completion: Downloading -> Seeding // Log status changes for debugging
if old_t.status == TorrentStatus::Downloading && new_t.status == TorrentStatus::Seeding { tracing::info!(
events.push(AppEvent::Notification(SystemNotification { "Torrent status changed: {} ({}) {:?} -> {:?}",
level: NotificationLevel::Success, new_t.name, new_t.hash, old_t.status, new_t.status
message: format!("Torrent tamamlandı: {}", new_t.name), );
}));
}
} }
if old_t.error_message != new_t.error_message { if old_t.error_message != new_t.error_message {
update.error_message = Some(new_t.error_message.clone()); update.error_message = Some(new_t.error_message.clone());