[PATCH] Improvements to the reliability of auto updates
authorYosuke Matsumura <yosukematsumura@gmail.com>
Tue, 8 Apr 2025 15:28:41 +0000 (08:28 -0700)
committerAurélien COUDERC <coucouf@debian.org>
Sun, 18 May 2025 22:58:38 +0000 (00:58 +0200)
Adding a wait to refreshUnattended to allow for modules to perform
update checks

Change refreshUnattended to use lastUnattendedTrigger instead of
lastNotificationTime as basis of determining whether to run.

BUG: 447245

Gbp-Pq: Name upstream_af0084b6_Improvements-to-the-reliability-of-auto-updates.patch

notifier/DiscoverNotifier.cpp
notifier/DiscoverNotifier.h

index 6ca1a393467da42db307d4f6bc11a6a9ab9729f3..ba4ae34600b72d5a6dac22385dd07675e600bbe0 100644 (file)
@@ -135,24 +135,33 @@ void DiscoverNotifier::showDiscoverUpdates(const QString &xdgActivationToken)
     }
 }
 
-bool DiscoverNotifier::notifyAboutUpdates() const
+bool DiscoverNotifier::checkTriggerTimes(const QDateTime &lastTriggerTime) const
 {
     if (state() != NormalUpdates && state() != SecurityUpdates) {
         // it's not very helpful to notify that everything is in order
-        qCDebug(NOTIFIER) << "Not notifying about updates, state is" << state();
+        qCDebug(NOTIFIER) << "Not triggering, state is" << state();
         return false;
     }
 
     if (m_settings->requiredNotificationInterval() < 0) {
-        qCDebug(NOTIFIER) << "Not notifying about updates, requiredNotificationInterval is" << m_settings->requiredNotificationInterval();
+        qCDebug(NOTIFIER) << "Not triggering, requiredNotificationInterval is" << m_settings->requiredNotificationInterval();
         return false;
     }
 
     // To configure to a random value, execute:
     // kwriteconfig5 --file PlasmaDiscoverUpdates --group Global --key RequiredNotificationInterval 3600
-    const QDateTime earliestNextNotificationTime = m_settings->lastNotificationTime().addSecs(m_settings->requiredNotificationInterval());
-    if (earliestNextNotificationTime.isValid() && earliestNextNotificationTime > QDateTime::currentDateTimeUtc()) {
-        qCDebug(NOTIFIER) << "Not notifying about updates, earliestNextNotificationTime is" << earliestNextNotificationTime;
+    const QDateTime earliestNextTriggerTime = lastTriggerTime.addSecs(m_settings->requiredNotificationInterval());
+    if (earliestNextTriggerTime.isValid() && earliestNextTriggerTime > QDateTime::currentDateTimeUtc()) {
+        qCDebug(NOTIFIER) << "Not triggering, earliestNextTriggerTime is" << earliestNextTriggerTime;
+        return false;
+    }
+
+    return true;
+}
+
+bool DiscoverNotifier::notifyAboutUpdates() const
+{
+    if (!checkTriggerTimes(m_settings->lastNotificationTime())) {
         return false;
     }
 
@@ -166,6 +175,19 @@ bool DiscoverNotifier::notifyAboutUpdates() const
     return true;
 }
 
+bool DiscoverNotifier::proceedUnattended() const
+{
+    if (!checkTriggerTimes(m_settings->lastUnattendedTrigger())) {
+        return false;
+    }
+
+    if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.discover"))) {
+        qCDebug(NOTIFIER) << "Not proceeding with unattended update, discover is running";
+        return false;
+    }
+    return true;
+}
+
 void DiscoverNotifier::showUpdatesNotification()
 {
     if (m_updatesAvailableNotification) {
@@ -240,7 +262,7 @@ void DiscoverNotifier::refreshUnattended()
 {
     m_settings->read();
 
-    if (!notifyAboutUpdates()) {
+    if (!proceedUnattended()) {
         qCDebug(NOTIFIER) << "refreshUnattended: not notifying about updates";
         return;
     }
@@ -321,7 +343,7 @@ void DiscoverNotifier::recheckSystemUpdateNeeded()
     for (BackendNotifierModule *module : std::as_const(m_backends))
         module->recheckSystemUpdateNeeded();
 
-    refreshUnattended();
+    QTimer::singleShot(20000, this, &DiscoverNotifier::refreshUnattended);
 }
 
 QStringList DiscoverNotifier::loadedModules() const
index 734abab72f3ce5d14bf13aaa51d20d8b0c5da0ba..47d251ed1c8f8e0b033c2f96df7bb6a63e9d09ca 100644 (file)
@@ -91,7 +91,9 @@ private:
     void updateStatusNotifier();
     void refreshUnattended();
 
+    bool checkTriggerTimes(const QDateTime &lastTriggerTime) const;
     bool notifyAboutUpdates() const;
+    bool proceedUnattended() const;
 
     QList<BackendNotifierModule *> m_backends;
     QTimer m_timer;