mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Slow download updates don't erase pending actions
... provided that download actions are inserted into the queue *before* existing update requests.
This commit is contained in:
parent
3c04e055bf
commit
262428e637
@ -37,6 +37,15 @@ DownloadState::Status getDownloadStatus(QString status)
|
||||
|
||||
} // unnamed namespace
|
||||
|
||||
bool DownloadState::isLateUpdateInfo(const DownloadInfo& info) const
|
||||
{
|
||||
if ( ! stateChangeHasBeenRequested() )
|
||||
return false;
|
||||
|
||||
const auto updateRequestTime = info["updateRequestTime"].toDouble();
|
||||
return updateRequestTime < lastUpdated.time_since_epoch().count();
|
||||
}
|
||||
|
||||
void DownloadState::update(const DownloadInfo& info)
|
||||
{
|
||||
const auto completedBytes = info["completedLength"].toDouble();
|
||||
@ -45,7 +54,9 @@ void DownloadState::update(const DownloadInfo& info)
|
||||
progress = QString::number(100 * percentage, 'g', 3).toDouble();
|
||||
completedLength = convertToUnits(completedBytes);
|
||||
downloadSpeed = convertToUnits(info["downloadSpeed"].toDouble()) + "/s";
|
||||
status = getDownloadStatus(info["status"].toString());
|
||||
if ( !isLateUpdateInfo(info) ) {
|
||||
status = getDownloadStatus(info["status"].toString());
|
||||
}
|
||||
lastUpdated = std::chrono::steady_clock::now();
|
||||
}
|
||||
|
||||
@ -161,6 +172,7 @@ void DownloadManager::restoreDownloads()
|
||||
|
||||
void DownloadManager::updateDownload(QString bookId)
|
||||
{
|
||||
const auto updateRequestTime = std::chrono::steady_clock::now();
|
||||
DownloadInfo downloadInfo;
|
||||
try {
|
||||
downloadInfo = getDownloadInfo(bookId);
|
||||
@ -169,6 +181,7 @@ void DownloadManager::updateDownload(QString bookId)
|
||||
return;
|
||||
}
|
||||
|
||||
downloadInfo["updateRequestTime"] = double(updateRequestTime.time_since_epoch().count());
|
||||
emit downloadUpdated(bookId, downloadInfo);
|
||||
}
|
||||
|
||||
|
@ -84,6 +84,13 @@ public: // functions
|
||||
QString getDownloadSpeed() const;
|
||||
Status getStatus() const { return status; }
|
||||
void changeState(Action action);
|
||||
bool stateChangeHasBeenRequested() const
|
||||
{
|
||||
return status == PAUSE_REQUESTED
|
||||
|| status == RESUME_REQUESTED
|
||||
|| status == CANCEL_REQUESTED;
|
||||
}
|
||||
bool isLateUpdateInfo(const DownloadInfo& info) const;
|
||||
|
||||
// time in seconds since last update
|
||||
double timeSinceLastUpdate() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user