Commit d607e0c6 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

notifier: Make sure we don't trigger offline updates too often

parent 86d2c7aa
Pipeline #134623 passed with stage
in 53 seconds
......@@ -14,5 +14,6 @@ SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted
<entry name="UseUnattendedUpdates" type="Bool">
<default>false</default>
</entry>
<entry name="LastUnattendedTrigger" type="DateTime" />
</group>
</kcfg>
......@@ -18,6 +18,7 @@
class KNotification;
class QNetworkConfigurationManager;
class UnattendedUpdates;
class UpdatesSettings;
class DiscoverNotifier : public QObject
{
......@@ -65,6 +66,10 @@ public:
{
return m_isBusy;
}
UpdatesSettings *settings() const
{
return m_settings;
}
public Q_SLOTS:
void recheckSystemUpdateNeeded();
......@@ -95,7 +100,7 @@ private:
QPointer<KNotification> m_updatesAvailableNotification;
UnattendedUpdates *m_unattended = nullptr;
KConfigWatcher::Ptr m_settingsWatcher;
class UpdatesSettings *m_settings;
UpdatesSettings *m_settings;
};
#endif // ABSTRACTKDEDMODULE_H
......@@ -6,6 +6,7 @@
#include "UnattendedUpdates.h"
#include "DiscoverNotifier.h"
#include "updatessettings.h"
#include <KIdleTime>
#include <QDateTime>
#include <QDebug>
......@@ -28,13 +29,27 @@ UnattendedUpdates::~UnattendedUpdates() noexcept
void UnattendedUpdates::checkNewState()
{
using namespace std::chrono_literals;
DiscoverNotifier *notifier = static_cast<DiscoverNotifier *>(parent());
// Only allow offline updating every 3h. It should keep some peace to our users, especially on rolling distros
const QDateTime updateableTime = notifier->settings()->lastUnattendedTrigger().addSecs((3h).count());
if (updateableTime > QDateTime::currentDateTimeUtc()) {
qDebug() << "skipping update, already updated on" << notifier->settings()->lastUnattendedTrigger().toString();
return;
}
if (!KIdleTime::instance()->idleTimeouts().isEmpty()) {
qDebug() << "already waiting for an idle time";
return;
}
if (notifier->hasUpdates()) {
qDebug() << "waiting for an idle moment";
// If the system is untouched for 1 hour, trigger the unattened update
using namespace std::chrono_literals;
// If the system is untouched for 15 minutes, trigger the unattened update
KIdleTime::instance()->addIdleTimeout(int(std::chrono::milliseconds(15min).count()));
} else {
qDebug() << "nothing to do";
KIdleTime::instance()->removeAllIdleTimeouts();
}
}
......@@ -56,6 +71,7 @@ void UnattendedUpdates::triggerUpdate()
DiscoverNotifier *notifier = static_cast<DiscoverNotifier *>(parent());
notifier->setBusy(false);
process->deleteLater();
notifier->settings()->setLastUnattendedTrigger(QDateTime::currentDateTimeUtc());
});
notifier->setBusy(true);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment