Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 85f574a

Browse files
committed
chore: update download event
1 parent 505cac8 commit 85f574a

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

engine/services/download_service.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void DownloadService::ProcessTask(DownloadTask& task) {
288288
fclose(pair.second);
289289
}
290290
downloading_data_map_.clear();
291+
auto copied_task = *active_task_;
291292
active_task_.reset();
292293

293294
RemoveTaskFromStopList(task.id);
@@ -298,15 +299,20 @@ void DownloadService::ProcessTask(DownloadTask& task) {
298299
event_queue_->enqueue(
299300
EventType::DownloadEvent,
300301
DownloadEvent{.type_ = DownloadEventType::DownloadStopped,
301-
.download_task_ = task});
302+
.download_task_ = copied_task});
302303
} else {
303304
CTL_INF("Executing callback..");
304305
ExecuteCallback(task);
305306

307+
// set all items to done
308+
for (auto& item : copied_task.items) {
309+
item.downloadedBytes = item.bytes;
310+
}
311+
306312
event_queue_->enqueue(
307313
EventType::DownloadEvent,
308314
DownloadEvent{.type_ = DownloadEventType::DownloadSuccess,
309-
.download_task_ = task});
315+
.download_task_ = copied_task});
310316
}
311317
}
312318

engine/services/download_service.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ class DownloadService {
149149
}
150150
}
151151

152+
auto all_items_bytes_greater_than_zero =
153+
std::all_of(active_task->items.begin(), active_task->items.end(),
154+
[](const DownloadItem& item) { return item.bytes > 0; });
155+
if (!all_items_bytes_greater_than_zero) {
156+
return 0;
157+
}
158+
152159
// Check if one second has passed since the last event
153160
static auto last_event_time = std::chrono::steady_clock::now();
154161
auto current_time = std::chrono::steady_clock::now();

0 commit comments

Comments
 (0)