mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-07 21:13:55 +00:00
committed by
Konstantin Pastbin
parent
c9cbb64f12
commit
76ffc99abd
45
libs/storage/downloading_policy.cpp
Normal file
45
libs/storage/downloading_policy.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "storage/downloading_policy.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
using namespace std::chrono;
|
||||
|
||||
void StorageDownloadingPolicy::EnableCellularDownload(bool enabled)
|
||||
{
|
||||
m_cellularDownloadEnabled = enabled;
|
||||
m_disableCellularTime = steady_clock::now() + hours(1);
|
||||
}
|
||||
|
||||
bool StorageDownloadingPolicy::IsCellularDownloadEnabled()
|
||||
{
|
||||
if (m_cellularDownloadEnabled && steady_clock::now() > m_disableCellularTime)
|
||||
m_cellularDownloadEnabled = false;
|
||||
|
||||
return m_cellularDownloadEnabled;
|
||||
}
|
||||
|
||||
bool StorageDownloadingPolicy::IsDownloadingAllowed()
|
||||
{
|
||||
return !(GetPlatform().ConnectionStatus() == Platform::EConnectionType::CONNECTION_WWAN &&
|
||||
!IsCellularDownloadEnabled());
|
||||
}
|
||||
|
||||
void StorageDownloadingPolicy::ScheduleRetry(storage::CountriesSet const & failedCountries,
|
||||
TProcessFunc const & func)
|
||||
{
|
||||
if (IsDownloadingAllowed() && !failedCountries.empty() && m_autoRetryCounter > 0)
|
||||
{
|
||||
m_downloadRetryFailed = false;
|
||||
auto action = [this, func, failedCountries] {
|
||||
--m_autoRetryCounter;
|
||||
func(failedCountries);
|
||||
};
|
||||
m_autoRetryWorker.RestartWith([action]{ GetPlatform().RunTask(Platform::Thread::Gui, action); });
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!failedCountries.empty())
|
||||
m_downloadRetryFailed = true;
|
||||
m_autoRetryCounter = kAutoRetryCounterMax;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user