Fix last update check date handling

This commit is contained in:
Gres 2020-04-05 14:34:47 +03:00
parent 56bacbfc7e
commit 071eadc088
2 changed files with 12 additions and 7 deletions

View File

@ -31,6 +31,7 @@ const auto updatesUrl =
Manager::Manager() Manager::Manager()
: settings_(std::make_unique<Settings>()) : settings_(std::make_unique<Settings>())
, updater_(std::make_unique<update::Loader>(QUrl(updatesUrl))) , updater_(std::make_unique<update::Loader>(QUrl(updatesUrl)))
, updateAutoChecker_(std::make_unique<update::AutoChecker>(*updater_))
, models_(std::make_unique<CommonModels>()) , models_(std::make_unique<CommonModels>())
{ {
SOFT_ASSERT(settings_, return ); SOFT_ASSERT(settings_, return );
@ -141,13 +142,9 @@ void Manager::setupUpdates(const Settings &settings)
{"$tessdata$", settings.tessdataPath}, {"$tessdata$", settings.tessdataPath},
}); });
if (settings.autoUpdateIntervalDays > 0) { SOFT_ASSERT(updateAutoChecker_, return );
updateAutoChecker_ = std::make_unique<update::AutoChecker>(*updater_);
updateAutoChecker_->setLastCheckDate(settings.lastUpdateCheck); updateAutoChecker_->setLastCheckDate(settings.lastUpdateCheck);
updateAutoChecker_->setCheckIntervalDays(settings.autoUpdateIntervalDays); updateAutoChecker_->setCheckIntervalDays(settings.autoUpdateIntervalDays);
} else {
updateAutoChecker_.reset();
}
} }
void Manager::setupTrace(bool isOn) void Manager::setupTrace(bool isOn)
@ -269,7 +266,12 @@ void Manager::translated(const TaskPtr &task)
void Manager::applySettings(const Settings &settings) void Manager::applySettings(const Settings &settings)
{ {
SOFT_ASSERT(settings_, return ); SOFT_ASSERT(settings_, return );
const auto lastUpdate = settings_->lastUpdateCheck; // not handled in editor
*settings_ = settings; *settings_ = settings;
settings_->lastUpdateCheck = lastUpdate;
settings_->save(); settings_->save();
updateSettings(); updateSettings();
} }

View File

@ -963,6 +963,9 @@ void AutoChecker::setLastCheckDate(const QDateTime &dt)
void AutoChecker::scheduleNextCheck() void AutoChecker::scheduleNextCheck()
{ {
if (timer_)
timer_->stop();
if (checkIntervalDays_ < 1 || !lastCheckDate_.isValid()) if (checkIntervalDays_ < 1 || !lastCheckDate_.isValid())
return; return;