Projects
Eulaceura:Factory
plasma-discover
_service:obs_scm:distro-upgrade.patch
Sign Up
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File _service:obs_scm:distro-upgrade.patch of Package plasma-discover
From 1944ac7d5735d71f542bb9f819aca8aa1821eb11 Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Wed, 1 Mar 2023 23:47:34 +0100 Subject: [PATCH 01/16] PackageKitBackend: Support distro upgrades Taking bits from RpmOstreeBackend --- .../PackageKitBackend/PackageKitBackend.cpp | 103 +++++++++++++++++- .../PackageKitBackend/PackageKitBackend.h | 6 + .../PackageKitBackend/PackageKitNotifier.cpp | 6 +- .../PackageKitBackend/PackageKitUpdater.cpp | 88 +++++++++++++-- .../PackageKitBackend/PackageKitUpdater.h | 2 + 5 files changed, 190 insertions(+), 15 deletions(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 3277a90a9..ee685765e 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -39,6 +39,8 @@ #include <KLocalizedString> #include <KProtocolManager> +#include <optional> + #include "config-paths.h" #include "libdiscover_backend_debug.h" #include "utils.h" @@ -183,7 +185,7 @@ PackageKitBackend::PackageKitBackend(QObject *parent) [this](uint timeSince) { if (timeSince > 3600) checkForUpdates(); - else + else if (!PackageKit::Daemon::global()->offline()->upgradeTriggered()) fetchUpdates(); acquireFetching(false); }, @@ -524,7 +526,7 @@ T PackageKitBackend::resourcesByPackageNames(const W &pkgnames) const void PackageKitBackend::checkForUpdates() { - if (PackageKit::Daemon::global()->offline()->updateTriggered()) { + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) { qCDebug(LIBDISCOVER_BACKEND_LOG) << "Won't be checking for updates again, the system needs a reboot to apply the fetched offline updates."; return; } @@ -775,7 +777,7 @@ bool PackageKitBackend::hasSecurityUpdates() const int PackageKitBackend::updatesCount() const { - if (PackageKit::Daemon::global()->offline()->updateTriggered()) + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) return 0; int ret = 0; @@ -885,6 +887,101 @@ void PackageKitBackend::getUpdatesFinished(PackageKit::Transaction::Exit, uint) connect(this, &PackageKitBackend::available, a, &OneTimeAction::trigger); } else Q_EMIT updatesCountChanged(); + + if (!m_updater->isDistroUpgrade() && !PackageKit::Daemon::global()->offline()->upgradeTriggered()) + lookForNextMajorVersion(); +} + +void PackageKitBackend::lookForNextMajorVersion() +{ + QString distroId = AppStream::Utils::currentDistroComponentId(); + + // Look at releases to see if we have a new major version available. + const QList<AppStream::Component> distroComponents = m_appdata->componentsById(distroId); + if (distroComponents.isEmpty()) { + qWarning() << "No component found for" << distroId; + return; + } + + QString currentVersion = AppStreamIntegration::global()->osRelease()->versionId(); + std::optional<AppStream::Release> nextRelease; + for (const AppStream::Component &dc : distroComponents) { + const auto releases = dc.releases(); + for (const auto &r : releases) { + // Only look at stable releases + if (r.kind() != AppStream::Release::KindStable) { + continue; + } + + // Let's look at this potentially new verson + const QString newVersion = r.version(); + if (AppStream::Utils::vercmpSimple(newVersion, currentVersion) > 0) { + if (!nextRelease) { + // No other newer version found yet so let's pick this one + nextRelease = r; + qInfo() << "Found new major release:" << newVersion; + } else if (AppStream::Utils::vercmpSimple(nextRelease->version(), newVersion) > 0) { + // We only offer updating to the very next major release so + // we pick the smallest of all the newest versions + nextRelease = r; + qInfo() << "Found a closer new major release:" << newVersion; + } + } + } + } + + if (nextRelease) { + foundNewMajorVersion(nextRelease.value()); + } +} + +void PackageKitBackend::foundNewMajorVersion(const AppStream::Release &release) +{ + QString info; + // Message to display when: + // - A new major version is available + // - An update to the current version is available or pending a reboot + info = i18n( + "<b>A new major version of %1 has been released.</b>\n" + "To be able to update to this new version, make sure to apply all updates and reboot your system.", + AppStreamIntegration::global()->osRelease()->name()); + QSharedPointer<InlineMessage> updateBeforeMajorUpgradeMessage = + QSharedPointer<InlineMessage>::create(InlineMessage::Positive, QStringLiteral("application-x-rpm"), info); + + // Message to display when: + // - A new major version is available + // - No update to the current version are available or pending a reboot + DiscoverAction *majorUpgrade = new DiscoverAction(i18n("Upgrade to %1 %2", AppStreamIntegration::global()->osRelease()->name(), release.version()), this); + connect(majorUpgrade, &DiscoverAction::triggered, this, [this, release] { + if (m_updater->isProgressing()) + return; + + const QString& upgradeVersion = release.version(); + m_updatesPackageId.clear(); + m_updater->setProgressing(true); + PackageKit::Transaction *transaction = PackageKit::Daemon::upgradeSystem(upgradeVersion, PackageKit::Transaction::UpgradeKind::UpgradeKindComplete, PackageKit::Transaction::TransactionFlagSimulate); + connect(transaction, &PackageKit::Transaction::package, this, &PackageKitBackend::addPackageToUpdate); + connect(transaction, &PackageKit::Transaction::percentageChanged, this, &PackageKitBackend::fetchingUpdatesProgressChanged); + connect(transaction, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError); + connect(transaction, &PackageKit::Transaction::finished, this, [this, release] (PackageKit::Transaction::Exit e, uint x){ + m_updater->setDistroUpgrade(release); + getUpdatesFinished(e, x); + }); + }); + + info = i18n("A new major version has been released"); + QSharedPointer<InlineMessage> majorUpgradeAvailableMessage = + QSharedPointer<InlineMessage>::create(InlineMessage::Positive, QStringLiteral("application-x-rpm"), info, majorUpgrade); + + // Allow upgrade only if up to date on the current release + if (!m_updatesPackageId.isEmpty()) { + Q_EMIT inlineMessageChanged(updateBeforeMajorUpgradeMessage); + return; + } + + // No updates pending or avaiable. We are good to offer the upgrade to the + // next major version! + Q_EMIT inlineMessageChanged(majorUpgradeAvailableMessage); } // Copy of Transaction::packageName that doesn't create a copy but just pass a reference diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h index d9a5fd824..b537a64f7 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h @@ -121,6 +121,10 @@ public: { return m_updateDetails; } + void clear() + { + m_updatesPackageId.clear(); + } public Q_SLOTS: void reloadPackageList(); @@ -156,6 +160,8 @@ private: void performDetailsFetch(const QSet<QString> &pkgids); AppPackageKitResource *addComponent(const AppStream::Component &component); void updateProxy(); + void lookForNextMajorVersion(); + void foundNewMajorVersion(const AppStream::Release &release); QScopedPointer<AppStream::Pool> m_appdata; PackageKitUpdater *m_updater; diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp index a5b62b60c..a8891d7e1 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp @@ -37,7 +37,7 @@ PackageKitNotifier::PackageKitNotifier(QObject *parent) connect(PackageKit::Daemon::global(), &PackageKit::Daemon::transactionListChanged, this, &PackageKitNotifier::transactionListChanged); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, this, &PackageKitNotifier::nowNeedsReboot); connect(PackageKit::Daemon::global()->offline(), &PackageKit::Offline::changed, this, [this] { - if (PackageKit::Daemon::global()->offline()->updateTriggered()) + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) nowNeedsReboot(); }); @@ -192,7 +192,7 @@ void PackageKitNotifier::recheckSystemUpdateNeeded() first = false; } - if (PackageKit::Daemon::global()->offline()->updateTriggered()) + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) return; m_recheckTimer->start(); @@ -317,7 +317,7 @@ QProcess *PackageKitNotifier::checkAptVariable(const QString &aptconfig, const Q void PackageKitNotifier::transactionListChanged(const QStringList &tids) { - if (PackageKit::Daemon::global()->offline()->updateTriggered()) + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) return; for (const auto &tid : tids) { diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index 276fc5056..c5c7e3755 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -5,12 +5,17 @@ */ #include "PackageKitUpdater.h" #include "PackageKitMessages.h" +#include <appstream/AppStreamIntegration.h> +#include <AppStreamQt/release.h> #include <PackageKit/Daemon> #include <PackageKit/Offline> #include <QCryptographicHash> #include <QDebug> #include <QSet> +#include <QDBusConnection> +#include <QDBusMessage> +#include <QDBusReply> #include <KConfigGroup> #include <KFormat> @@ -18,6 +23,8 @@ #include <KLocalizedString> #include <KSharedConfig> +#include <optional> + #include "libdiscover_backend_debug.h" #include "pk-offline-private.h" #include "utils.h" @@ -82,6 +89,9 @@ public: } QString name() const override { + if (isDistroUpgrade()) { + return i18nc("distro upgrade: name version", "%1 %2", AppStreamIntegration::global()->osRelease()->name(), m_distroUpgrade->version()); + } return i18n("System upgrade"); } QString comment() override @@ -134,6 +144,10 @@ public: quint64 size() override { quint64 ret = 0; + if (isDistroUpgrade()) { + return ret; + } + const auto resources = withoutDuplicates(); for (auto res : resources) { ret += res->size(); @@ -187,10 +201,18 @@ public: } } changes.sort(); + + if (isDistroUpgrade()) { + changes.prepend(m_distroUpgrade->description()); + } return changes.join(QString()); } void fetchChangelog() override { + if (isDistroUpgrade()) { + return; + } + for (auto res : qAsConst(m_resources)) { res->fetchUpdateDetails(); } @@ -257,6 +279,21 @@ public: } } + void setDistroUpgrade(const AppStream::Release &release) + { + m_distroUpgrade = release; + } + + bool isDistroUpgrade() const + { + return m_distroUpgrade.has_value(); + } + + const AppStream::Release& getDistroUpgrade() + { + return m_distroUpgrade.value(); + } + Q_SIGNALS: void updateSizeChanged(); @@ -264,6 +301,7 @@ private: QSet<AbstractResource *> m_resources; PackageKitBackend *const m_backend; QTimer *m_updateSizeTimer; + std::optional<AppStream::Release> m_distroUpgrade; }; PackageKitUpdater::PackageKitUpdater(PackageKitBackend *parent) @@ -285,7 +323,7 @@ PackageKitUpdater::~PackageKitUpdater() void PackageKitUpdater::prepare() { - if (PackageKit::Daemon::global()->offline()->updateTriggered()) { + if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) { m_toUpgrade.clear(); m_allUpgradeable.clear(); enableNeedsReboot(); @@ -327,9 +365,14 @@ void PackageKitUpdater::checkFreeSpace() void PackageKitUpdater::setupTransaction(PackageKit::Transaction::TransactionFlags flags) { m_packagesModified.clear(); - auto pkgs = involvedPackages(m_toUpgrade).values(); - pkgs.sort(); - m_transaction = PackageKit::Daemon::updatePackages(pkgs, flags); + if (m_toUpgrade.contains(m_upgrade) && m_upgrade->isDistroUpgrade()) { + const QString& upgradeVersion = m_upgrade->getDistroUpgrade().version(); + m_transaction = PackageKit::Daemon::upgradeSystem(upgradeVersion, PackageKit::Transaction::UpgradeKind::UpgradeKindComplete, flags); + } else { + auto pkgs = involvedPackages(m_toUpgrade).values(); + pkgs.sort(); + m_transaction = PackageKit::Daemon::updatePackages(pkgs, flags); + } m_isCancelable = m_transaction->allowCancel(); cancellableChanged(); @@ -430,7 +473,7 @@ void PackageKitUpdater::proceed() bool PackageKitUpdater::useOfflineUpdates() const { - return m_useOfflineUpdates || qEnvironmentVariableIntValue("PK_OFFLINE_UPDATE"); + return m_useOfflineUpdates || m_upgrade->isDistroUpgrade() || qEnvironmentVariableIntValue("PK_OFFLINE_UPDATE"); } void PackageKitUpdater::setOfflineUpdates(bool use) @@ -438,6 +481,16 @@ void PackageKitUpdater::setOfflineUpdates(bool use) m_useOfflineUpdates = use; } +void PackageKitUpdater::setDistroUpgrade(const AppStream::Release &release) +{ + m_upgrade->setDistroUpgrade(release); +} + +bool PackageKitUpdater::isDistroUpgrade() const +{ + return m_upgrade->isDistroUpgrade(); +} + void PackageKitUpdater::start() { Q_ASSERT(!isProgressing()); @@ -523,12 +576,29 @@ void PackageKitUpdater::finished(PackageKit::Transaction::Exit exit, uint /*time return; } - setProgressing(false); - m_backend->fetchUpdates(); - fetchLastUpdateTime(); + // Fetching updates now would clear the prepared-upgrade + if (!m_toUpgrade.contains(m_upgrade) || !m_upgrade->isDistroUpgrade()) { + setProgressing(false); + m_backend->fetchUpdates(); + fetchLastUpdateTime(); + } if (useOfflineUpdates() && exit == PackageKit::Transaction::ExitSuccess) { - PackageKit::Daemon::global()->offline()->trigger(PackageKit::Offline::ActionReboot); + if (m_upgrade->isDistroUpgrade()) { + QDBusPendingReply<void> reply = PackageKit::Daemon::global()->offline()->triggerUpgrade(PackageKit::Offline::ActionReboot); + // Call may fail because of authorization + reply.waitForFinished(); + if (reply.isError()) { + Q_EMIT resourceProgressed(m_upgrade, 0, None); + setProgressing(false); + Q_EMIT passiveMessage(reply.error().message()); + return; + } + m_backend->clear(); + setProgressing(false); + } else { + PackageKit::Daemon::global()->offline()->trigger(PackageKit::Offline::ActionReboot); + } enableReadyToReboot(); } } diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h index 3117cf2da..4b75a472d 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h @@ -46,6 +46,8 @@ public: void proceed() override; void setOfflineUpdates(bool use) override; + void setDistroUpgrade(const AppStream::Release &release); + bool isDistroUpgrade() const; public Q_SLOTS: /// must be implemented if ever isCancelable is true -- 2.41.0 From 5f37b9467ccb40cfc57b29bfa8bf48f06c81ffa5 Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Thu, 23 Mar 2023 17:08:02 +0100 Subject: [PATCH 02/16] PackageKitNotifier: Prevent calling getUpdates if distro upgrade is triggered Calling getUpdates cancels a triggered distro upgrade We check the same condition in `recheckSystemUpdateNeeded` but only call `recheckSystemUpdate` up to 200ms later, in which time an upgrade may have been triggered --- libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp index a8891d7e1..36f860457 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp @@ -200,7 +200,7 @@ void PackageKitNotifier::recheckSystemUpdateNeeded() void PackageKitNotifier::recheckSystemUpdate() { - if (PackageKit::Daemon::global()->isRunning()) { + if (PackageKit::Daemon::global()->isRunning() && !PackageKit::Daemon::global()->offline()->upgradeTriggered()) { PackageKit::Daemon::getUpdates(); } } -- 2.41.0 From 73059dfd9a8e758d05a50312ecb3a8e7504f1202 Mon Sep 17 00:00:00 2001 From: Nate Graham <nate@kde.org> Date: Sat, 25 Mar 2023 07:55:28 -0600 Subject: [PATCH 03/16] Massage distro upgrade string --- libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index ee685765e..83d323192 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -943,7 +943,7 @@ void PackageKitBackend::foundNewMajorVersion(const AppStream::Release &release) // - An update to the current version is available or pending a reboot info = i18n( "<b>A new major version of %1 has been released.</b>\n" - "To be able to update to this new version, make sure to apply all updates and reboot your system.", + "To be able to upgrade to this new version, make sure to apply all available updates and then restart the system.", AppStreamIntegration::global()->osRelease()->name()); QSharedPointer<InlineMessage> updateBeforeMajorUpgradeMessage = QSharedPointer<InlineMessage>::create(InlineMessage::Positive, QStringLiteral("application-x-rpm"), info); -- 2.41.0 From f9da18bae36161bc794ab4d158f607fee92addd7 Mon Sep 17 00:00:00 2001 From: Aleix Pol <aleixpol@kde.org> Date: Mon, 1 May 2023 06:16:53 +0200 Subject: [PATCH 04/16] pk: Clear upgrade inline message when it has already been acted on BUG: 469157 --- libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 83d323192..200da4aa4 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -967,6 +967,7 @@ void PackageKitBackend::foundNewMajorVersion(const AppStream::Release &release) m_updater->setDistroUpgrade(release); getUpdatesFinished(e, x); }); + Q_EMIT inlineMessageChanged({}); }); info = i18n("A new major version has been released"); -- 2.41.0 From a551b814ea1962702fa26fc1db5298a4026d1454 Mon Sep 17 00:00:00 2001 From: Aleix Pol <aleixpol@kde.org> Date: Wed, 3 May 2023 00:17:54 +0200 Subject: [PATCH 05/16] pk: Switch to the updates view when an upgrade is triggered BUG: 469156 --- discover/qml/DiscoverWindow.qml | 3 +++ libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp | 2 ++ libdiscover/resources/ResourcesModel.h | 1 + 3 files changed, 6 insertions(+) diff --git a/discover/qml/DiscoverWindow.qml b/discover/qml/DiscoverWindow.qml index 8c4aadce4..ba158bba7 100644 --- a/discover/qml/DiscoverWindow.qml +++ b/discover/qml/DiscoverWindow.qml @@ -155,6 +155,9 @@ Kirigami.ApplicationWindow Connections { target: ResourcesModel + function onSwitchToUpdates() { + window.currentTopLevel = topUpdateComp + } function onPassiveMessage(message) { messagesSheet.addMessage(message); } diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 200da4aa4..970bb097f 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -45,6 +45,7 @@ #include "libdiscover_backend_debug.h" #include "utils.h" #include <Category/Category.h> +#include <resources/ResourcesModel.h> DISCOVER_BACKEND_PLUGIN(PackageKitBackend) @@ -968,6 +969,7 @@ void PackageKitBackend::foundNewMajorVersion(const AppStream::Release &release) getUpdatesFinished(e, x); }); Q_EMIT inlineMessageChanged({}); + ResourcesModel::global()->switchToUpdates(); }); info = i18n("A new major version has been released"); diff --git a/libdiscover/resources/ResourcesModel.h b/libdiscover/resources/ResourcesModel.h index b086619c9..928f77f52 100644 --- a/libdiscover/resources/ResourcesModel.h +++ b/libdiscover/resources/ResourcesModel.h @@ -143,6 +143,7 @@ Q_SIGNALS: void currentApplicationBackendChanged(AbstractResourcesBackend *currentApplicationBackend); void fetchingUpdatesProgressChanged(int fetchingUpdatesProgress); void inlineMessageChanged(const QSharedPointer<InlineMessage> &inlineMessage); + void switchToUpdates(); private Q_SLOTS: void callerFetchingChanged(); -- 2.41.0 From 3c4190f4ad47c56711bf6ae8de184c0b4c6c824c Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Mon, 17 Jul 2023 20:19:59 +0200 Subject: [PATCH 06/16] appstream: Make AppStreamIntegration a self contained library AppStreamIntegration is a singleton that provided reviews as a local OdrsReviewsBackend object. The same can be achieved by making OdrsReviewsBackend a singleton itself. Enables notifiers to use it, without having to link to DiscoverCommon --- discover/OdrsAppsModel.cpp | 6 +++--- libdiscover/CMakeLists.txt | 8 ++++++++ libdiscover/appstream/AppStreamIntegration.cpp | 12 ------------ libdiscover/appstream/AppStreamIntegration.h | 3 --- libdiscover/appstream/OdrsReviewsBackend.cpp | 10 ++++++++++ libdiscover/appstream/OdrsReviewsBackend.h | 1 + .../backends/FlatpakBackend/FlatpakBackend.cpp | 3 +-- .../backends/PackageKitBackend/PackageKitBackend.cpp | 2 +- libdiscover/backends/SnapBackend/SnapBackend.cpp | 4 ++-- 9 files changed, 26 insertions(+), 23 deletions(-) diff --git a/discover/OdrsAppsModel.cpp b/discover/OdrsAppsModel.cpp index 46b0b0eaa..4fb9d5373 100644 --- a/discover/OdrsAppsModel.cpp +++ b/discover/OdrsAppsModel.cpp @@ -5,13 +5,13 @@ */ #include "OdrsAppsModel.h" -#include "appstream/AppStreamIntegration.h" #include <ReviewsBackend/Rating.h> +#include <appstream/OdrsReviewsBackend.h> #include <utils.h> OdrsAppsModel::OdrsAppsModel() { - auto x = AppStreamIntegration::global()->reviews(); + auto x = OdrsReviewsBackend::global(); connect(x.get(), &OdrsReviewsBackend::ratingsReady, this, &OdrsAppsModel::refresh); if (!x->top().isEmpty()) { refresh(); @@ -20,7 +20,7 @@ OdrsAppsModel::OdrsAppsModel() void OdrsAppsModel::refresh() { - const auto top = AppStreamIntegration::global()->reviews()->top(); + const auto top = OdrsReviewsBackend::global()->top(); setUris(kTransform<QVector<QUrl>>(top, [](auto r) { return QUrl("appstream://" + r->packageName()); })); diff --git a/libdiscover/CMakeLists.txt b/libdiscover/CMakeLists.txt index 32c49f339..549de813e 100644 --- a/libdiscover/CMakeLists.txt +++ b/libdiscover/CMakeLists.txt @@ -6,6 +6,14 @@ add_subdirectory(backends) add_subdirectory(notifiers) add_subdirectory(tests) +if (TARGET AppStreamQt) + add_library(DiscoverAppStreamIntegration STATIC + appstream/AppStreamIntegration.cpp + ) + target_link_libraries(DiscoverAppStreamIntegration KF5::CoreAddons AppStreamQt) + set_property(TARGET DiscoverAppStreamIntegration PROPERTY POSITION_INDEPENDENT_CODE ON) +endif() + set(discovercommon_SRCS Category/Category.cpp Category/CategoryModel.cpp diff --git a/libdiscover/appstream/AppStreamIntegration.cpp b/libdiscover/appstream/AppStreamIntegration.cpp index 046f8c757..d4134d171 100644 --- a/libdiscover/appstream/AppStreamIntegration.cpp +++ b/libdiscover/appstream/AppStreamIntegration.cpp @@ -15,15 +15,3 @@ AppStreamIntegration *AppStreamIntegration::global() return var; } - -QSharedPointer<OdrsReviewsBackend> AppStreamIntegration::reviews() -{ - QSharedPointer<OdrsReviewsBackend> ret; - if (m_reviews) { - ret = m_reviews; - } else { - ret = QSharedPointer<OdrsReviewsBackend>(new OdrsReviewsBackend()); - m_reviews = ret; - } - return ret; -} diff --git a/libdiscover/appstream/AppStreamIntegration.h b/libdiscover/appstream/AppStreamIntegration.h index 1c1cf7fb1..57904b363 100644 --- a/libdiscover/appstream/AppStreamIntegration.h +++ b/libdiscover/appstream/AppStreamIntegration.h @@ -6,7 +6,6 @@ #pragma once -#include "OdrsReviewsBackend.h" #include "discovercommon_export.h" #include <KOSRelease> #include <QObject> @@ -17,14 +16,12 @@ class DISCOVERCOMMON_EXPORT AppStreamIntegration : public QObject public: static AppStreamIntegration *global(); - QSharedPointer<OdrsReviewsBackend> reviews(); KOSRelease *osRelease() { return &m_osrelease; } private: - QSharedPointer<OdrsReviewsBackend> m_reviews; KOSRelease m_osrelease; AppStreamIntegration() diff --git a/libdiscover/appstream/OdrsReviewsBackend.cpp b/libdiscover/appstream/OdrsReviewsBackend.cpp index c54490b9f..4054b3dc6 100644 --- a/libdiscover/appstream/OdrsReviewsBackend.cpp +++ b/libdiscover/appstream/OdrsReviewsBackend.cpp @@ -38,6 +38,16 @@ // #define APIURL "http://127.0.0.1:5000/1.0/reviews/api" #define APIURL "https://odrs.gnome.org/1.0/reviews/api" +QSharedPointer<OdrsReviewsBackend> OdrsReviewsBackend::global() +{ + static QSharedPointer<OdrsReviewsBackend> var = nullptr; + if (!var) { + var = QSharedPointer<OdrsReviewsBackend>(new OdrsReviewsBackend()); + } + + return var; +} + OdrsReviewsBackend::OdrsReviewsBackend() : AbstractReviewsBackend(nullptr) { diff --git a/libdiscover/appstream/OdrsReviewsBackend.h b/libdiscover/appstream/OdrsReviewsBackend.h index 8e36af8b4..6309d2eb4 100644 --- a/libdiscover/appstream/OdrsReviewsBackend.h +++ b/libdiscover/appstream/OdrsReviewsBackend.h @@ -22,6 +22,7 @@ class DISCOVERCOMMON_EXPORT OdrsReviewsBackend : public AbstractReviewsBackend { Q_OBJECT public: + static QSharedPointer<OdrsReviewsBackend> global(); explicit OdrsReviewsBackend(); ~OdrsReviewsBackend() override; diff --git a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp index 99488469b..6cf339274 100644 --- a/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp +++ b/libdiscover/backends/FlatpakBackend/FlatpakBackend.cpp @@ -13,7 +13,6 @@ #include <ReviewsBackend/Rating.h> #include <Transaction/Transaction.h> -#include <appstream/AppStreamIntegration.h> #include <appstream/AppStreamUtils.h> #include <appstream/OdrsReviewsBackend.h> #include <resources/SourcesModel.h> @@ -286,7 +285,7 @@ static std::optional<AppStream::Metadata> metadataFromBytes(GBytes *appstreamGz, FlatpakBackend::FlatpakBackend(QObject *parent) : AbstractResourcesBackend(parent) , m_updater(new StandardBackendUpdater(this)) - , m_reviews(AppStreamIntegration::global()->reviews()) + , m_reviews(OdrsReviewsBackend::global()) , m_cancellable(g_cancellable_new()) , m_checkForUpdatesTimer(new QTimer(this)) { diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 970bb097f..bc6fcbc97 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -102,7 +102,7 @@ PackageKitBackend::PackageKitBackend(QObject *parent) , m_updater(new PackageKitUpdater(this)) , m_refresher(nullptr) , m_isFetching(0) - , m_reviews(AppStreamIntegration::global()->reviews()) + , m_reviews(OdrsReviewsBackend::global()) { QTimer *t = new QTimer(this); connect(t, &QTimer::timeout, this, &PackageKitBackend::checkForUpdates); diff --git a/libdiscover/backends/SnapBackend/SnapBackend.cpp b/libdiscover/backends/SnapBackend/SnapBackend.cpp index 8d4c829dc..fb316d725 100644 --- a/libdiscover/backends/SnapBackend/SnapBackend.cpp +++ b/libdiscover/backends/SnapBackend/SnapBackend.cpp @@ -7,10 +7,10 @@ #include "SnapBackend.h" #include "SnapResource.h" #include "SnapTransaction.h" -#include "appstream/AppStreamIntegration.h" #include <Category/Category.h> #include <Transaction/Transaction.h> #include <appstream/AppStreamUtils.h> +#include <appstream/OdrsReviewsBackend.h> #include <resources/SourcesModel.h> #include <resources/StandardBackendUpdater.h> #include <resources/StoredResultsStream.h> @@ -82,7 +82,7 @@ private: SnapBackend::SnapBackend(QObject *parent) : AbstractResourcesBackend(parent) , m_updater(new StandardBackendUpdater(this)) - , m_reviews(AppStreamIntegration::global()->reviews()) + , m_reviews(OdrsReviewsBackend::global()) { connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, [this] { m_reviews->emitRatingFetched(this, kTransform<QList<AbstractResource *>>(m_resources.values(), [](AbstractResource *r) { -- 2.41.0 From a1ff3561e1e1ed7dc65060708059bae8a149a289 Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Sun, 16 Jul 2023 18:08:09 +0200 Subject: [PATCH 07/16] pk: Notify of a new distro upgrade from AppStream PackageKitNotifier already had the logic to notify of a distro upgrade from PackageKit::Daemon::getDistroUpgrades(). However, not all pk backends implement that that. In the PackageKitBackend we already implemented upgrading using versions from AppStream, so check the same metadata in the notifier. I have no evidence that the old code path was actually being used by anyone: in facts the notification was misconfigured and thus couldn't be shown, on modern KF versions at the least. Nonetheless the old logic remains intact while this is implemented in parallel. Contrary to the old logic that invokes PackageKit::Daemon::upgradeSystem(version) immediatly without showing any progress indicator, this notification simply launches the discover UI where the already present upgrade logic will guide the user through an informed distro upgrade. --- .../appstream/AppStreamIntegration.cpp | 45 +++++++++++++++++ libdiscover/appstream/AppStreamIntegration.h | 6 +++ .../backends/PackageKitBackend/CMakeLists.txt | 2 +- .../PackageKitBackend/PackageKitBackend.cpp | 48 ++----------------- .../PackageKitBackend/PackageKitBackend.h | 1 - .../PackageKitBackend/PackageKitNotifier.cpp | 26 +++++++++- .../PackageKitBackend/PackageKitNotifier.h | 4 ++ libdiscover/notifiers/BackendNotifierModule.h | 1 + .../discoverabstractnotifier.notifyrc | 5 ++ notifier/DiscoverNotifier.cpp | 14 +++++- 10 files changed, 103 insertions(+), 49 deletions(-) diff --git a/libdiscover/appstream/AppStreamIntegration.cpp b/libdiscover/appstream/AppStreamIntegration.cpp index d4134d171..0852c7560 100644 --- a/libdiscover/appstream/AppStreamIntegration.cpp +++ b/libdiscover/appstream/AppStreamIntegration.cpp @@ -6,6 +6,10 @@ #include "AppStreamIntegration.h" +#include <AppStreamQt/utils.h> +#include <AppStreamQt/version.h> +#include <QDebug> + AppStreamIntegration *AppStreamIntegration::global() { static AppStreamIntegration *var = nullptr; @@ -15,3 +19,44 @@ AppStreamIntegration *AppStreamIntegration::global() return var; } + +std::optional<AppStream::Release> AppStreamIntegration::getDistroUpgrade(AppStream::Pool *pool) +{ + QString distroId = AppStream::Utils::currentDistroComponentId(); + + // Look at releases to see if we have a new major version available. + const QList<AppStream::Component> distroComponents = pool->componentsById(distroId); + if (distroComponents.isEmpty()) { + qWarning() << "No component found for" << distroId; + return std::nullopt; + } + + QString currentVersion = osRelease()->versionId(); + std::optional<AppStream::Release> nextRelease; + for (const AppStream::Component &dc : distroComponents) { + const auto releases = dc.releases(); + for (const auto &r : releases) { + // Only look at stable releases + if (r.kind() != AppStream::Release::KindStable) { + continue; + } + + // Let's look at this potentially new verson + const QString newVersion = r.version(); + if (AppStream::Utils::vercmpSimple(newVersion, currentVersion) > 0) { + if (!nextRelease) { + // No other newer version found yet so let's pick this one + nextRelease = r; + qInfo() << "Found new major release:" << newVersion; + } else if (AppStream::Utils::vercmpSimple(nextRelease->version(), newVersion) > 0) { + // We only offer updating to the very next major release so + // we pick the smallest of all the newest versions + nextRelease = r; + qInfo() << "Found a closer new major release:" << newVersion; + } + } + } + } + + return nextRelease; +} diff --git a/libdiscover/appstream/AppStreamIntegration.h b/libdiscover/appstream/AppStreamIntegration.h index 57904b363..78454b944 100644 --- a/libdiscover/appstream/AppStreamIntegration.h +++ b/libdiscover/appstream/AppStreamIntegration.h @@ -7,15 +7,21 @@ #pragma once #include "discovercommon_export.h" + +#include <AppStreamQt/pool.h> +#include <AppStreamQt/release.h> #include <KOSRelease> #include <QObject> +#include <optional> + class DISCOVERCOMMON_EXPORT AppStreamIntegration : public QObject { Q_OBJECT public: static AppStreamIntegration *global(); + std::optional<AppStream::Release> getDistroUpgrade(AppStream::Pool *pool); KOSRelease *osRelease() { return &m_osrelease; diff --git a/libdiscover/backends/PackageKitBackend/CMakeLists.txt b/libdiscover/backends/PackageKitBackend/CMakeLists.txt index 415407fc1..b23809024 100644 --- a/libdiscover/backends/PackageKitBackend/CMakeLists.txt +++ b/libdiscover/backends/PackageKitBackend/CMakeLists.txt @@ -33,7 +33,7 @@ ecm_qt_declare_logging_category(DiscoverPackageKitNotifier_SRCS HEADER libdiscov add_library(DiscoverPackageKitNotifier MODULE ${DiscoverPackageKitNotifier_SRCS}) -target_link_libraries(DiscoverPackageKitNotifier PRIVATE PK::packagekitqt5 Discover::Notifiers KF5::I18n KF5::Notifications KF5::ConfigCore) +target_link_libraries(DiscoverPackageKitNotifier PRIVATE PK::packagekitqt5 Discover::Notifiers KF5::I18n KF5::Notifications KF5::ConfigCore DiscoverAppStreamIntegration) set_target_properties(DiscoverPackageKitNotifier PROPERTIES INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}/plasma-discover) install(TARGETS DiscoverPackageKitNotifier DESTINATION ${KDE_INSTALL_PLUGINDIR}/discover-notifier) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index bc6fcbc97..58fe44de6 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -889,50 +889,10 @@ void PackageKitBackend::getUpdatesFinished(PackageKit::Transaction::Exit, uint) } else Q_EMIT updatesCountChanged(); - if (!m_updater->isDistroUpgrade() && !PackageKit::Daemon::global()->offline()->upgradeTriggered()) - lookForNextMajorVersion(); -} - -void PackageKitBackend::lookForNextMajorVersion() -{ - QString distroId = AppStream::Utils::currentDistroComponentId(); - - // Look at releases to see if we have a new major version available. - const QList<AppStream::Component> distroComponents = m_appdata->componentsById(distroId); - if (distroComponents.isEmpty()) { - qWarning() << "No component found for" << distroId; - return; - } - - QString currentVersion = AppStreamIntegration::global()->osRelease()->versionId(); - std::optional<AppStream::Release> nextRelease; - for (const AppStream::Component &dc : distroComponents) { - const auto releases = dc.releases(); - for (const auto &r : releases) { - // Only look at stable releases - if (r.kind() != AppStream::Release::KindStable) { - continue; - } - - // Let's look at this potentially new verson - const QString newVersion = r.version(); - if (AppStream::Utils::vercmpSimple(newVersion, currentVersion) > 0) { - if (!nextRelease) { - // No other newer version found yet so let's pick this one - nextRelease = r; - qInfo() << "Found new major release:" << newVersion; - } else if (AppStream::Utils::vercmpSimple(nextRelease->version(), newVersion) > 0) { - // We only offer updating to the very next major release so - // we pick the smallest of all the newest versions - nextRelease = r; - qInfo() << "Found a closer new major release:" << newVersion; - } - } - } - } - - if (nextRelease) { - foundNewMajorVersion(nextRelease.value()); + if (!m_updater->isDistroUpgrade() && !PackageKit::Daemon::global()->offline()->upgradeTriggered()) { + auto nextRelease = AppStreamIntegration::global()->getDistroUpgrade(m_appdata.get()); + if (nextRelease) + foundNewMajorVersion(*nextRelease); } } diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h index b537a64f7..5dc7fa235 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h @@ -160,7 +160,6 @@ private: void performDetailsFetch(const QSet<QString> &pkgids); AppPackageKitResource *addComponent(const AppStream::Component &component); void updateProxy(); - void lookForNextMajorVersion(); void foundNewMajorVersion(const AppStream::Release &release); QScopedPointer<AppStream::Pool> m_appdata; diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp index 36f860457..ca3afb51e 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp @@ -23,6 +23,10 @@ #include <QTextStream> #include <QTimer> +#include <AppStreamQt/pool.h> +#include <AppStreamQt/release.h> +#include <appstream/AppStreamIntegration.h> + #include "libdiscover_backend_debug.h" #include "pk-offline-private.h" @@ -32,6 +36,8 @@ PackageKitNotifier::PackageKitNotifier(QObject *parent) : BackendNotifierModule(parent) , m_securityUpdates(0) , m_normalUpdates(0) + , m_hasDistUpgrade(false) + , m_appdata(new AppStream::Pool) { connect(PackageKit::Daemon::global(), &PackageKit::Daemon::updatesChanged, this, &PackageKitNotifier::recheckSystemUpdateNeeded); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::transactionListChanged, this, &PackageKitNotifier::transactionListChanged); @@ -41,6 +47,8 @@ PackageKitNotifier::PackageKitNotifier(QObject *parent) nowNeedsReboot(); }); + m_appdata->load(); + // Check if there's packages after 5' QTimer::singleShot(5min, this, &PackageKitNotifier::refreshDatabase); @@ -249,7 +257,7 @@ void PackageKitNotifier::finished(PackageKit::Transaction::Exit /*exit*/, uint) bool PackageKitNotifier::hasUpdates() { - return m_normalUpdates > 0; + return m_normalUpdates > 0 || m_hasDistUpgrade; } bool PackageKitNotifier::hasSecurityUpdates() @@ -259,6 +267,7 @@ bool PackageKitNotifier::hasSecurityUpdates() void PackageKitNotifier::onDistroUpgrade(PackageKit::Transaction::DistroUpgrade /*type*/, const QString &name, const QString &description) { + m_hasDistUpgrade = true; auto a = new UpgradeAction(name, description, this); connect(a, &UpgradeAction::triggered, this, [](const QString &name) { PackageKit::Daemon::upgradeSystem(name, PackageKit::Transaction::UpgradeKindDefault); @@ -266,6 +275,20 @@ void PackageKitNotifier::onDistroUpgrade(PackageKit::Transaction::DistroUpgrade Q_EMIT foundUpgradeAction(a); } +void PackageKitNotifier::fallbackCheckDistroUpgrade() +{ + auto nextRelease = AppStreamIntegration::global()->getDistroUpgrade(m_appdata.get()); + if (nextRelease) { + m_hasDistUpgrade = true; + const QString &fullName = QStringLiteral("%1 %2").arg(AppStreamIntegration::global()->osRelease()->name(), nextRelease->version()); + auto a = new UpgradeAction(nextRelease->version(), fullName, this); + connect(a, &UpgradeAction::triggered, this, [a](const QString &) { + Q_EMIT a->showDiscoverUpdates(); + }); + Q_EMIT foundUpgradeAction(a); + } +} + void PackageKitNotifier::refreshDatabase() { if (auto offline = PackageKit::Daemon::global()->offline(); @@ -288,6 +311,7 @@ void PackageKitNotifier::refreshDatabase() if (!m_distUpgrades && (PackageKit::Daemon::roles() & PackageKit::Transaction::RoleUpgradeSystem)) { m_distUpgrades = PackageKit::Daemon::getDistroUpgrades(); connect(m_distUpgrades, &PackageKit::Transaction::distroUpgrade, this, &PackageKitNotifier::onDistroUpgrade); + connect(m_distUpgrades, &PackageKit::Transaction::errorCode, this, &PackageKitNotifier::fallbackCheckDistroUpgrade); } } diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h index f9bcd5095..43ff904cf 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h @@ -5,6 +5,7 @@ */ #pragma once +#include <AppStreamQt/pool.h> #include <BackendNotifierModule.h> #include <PackageKit/Transaction> #include <QPointer> @@ -31,6 +32,7 @@ public: { return m_needsReboot; } + void fallbackCheckDistroUpgrade(); private Q_SLOTS: void package(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary); @@ -49,9 +51,11 @@ private: bool m_needsReboot = false; uint m_securityUpdates; uint m_normalUpdates; + bool m_hasDistUpgrade; QPointer<PackageKit::Transaction> m_refresher; QPointer<PackageKit::Transaction> m_distUpgrades; QTimer *m_recheckTimer; QHash<QString, PackageKit::Transaction *> m_transactions; + std::unique_ptr<AppStream::Pool> m_appdata; }; diff --git a/libdiscover/notifiers/BackendNotifierModule.h b/libdiscover/notifiers/BackendNotifierModule.h index 58a46d95e..2bb20ee0d 100644 --- a/libdiscover/notifiers/BackendNotifierModule.h +++ b/libdiscover/notifiers/BackendNotifierModule.h @@ -39,6 +39,7 @@ public: Q_SIGNALS: void triggered(const QString &name); + void showDiscoverUpdates(); private: const QString m_name; diff --git a/libdiscover/resources/discoverabstractnotifier.notifyrc b/libdiscover/resources/discoverabstractnotifier.notifyrc index c90792e2e..b1bd51613 100644 --- a/libdiscover/resources/discoverabstractnotifier.notifyrc +++ b/libdiscover/resources/discoverabstractnotifier.notifyrc @@ -579,3 +579,8 @@ Name[zh_CN]=需要重启 Name[zh_TW]=需要重新啟動電腦 Urgency=High Action=Popup + +[Event/DistUpgrade] +Name=Upgrade available +Urgency=High +Action=Popup diff --git a/notifier/DiscoverNotifier.cpp b/notifier/DiscoverNotifier.cpp index 56aeb0976..70d29046c 100644 --- a/notifier/DiscoverNotifier.cpp +++ b/notifier/DiscoverNotifier.cpp @@ -337,12 +337,22 @@ void DiscoverNotifier::reboot() void DiscoverNotifier::foundUpgradeAction(UpgradeAction *action) { - KNotification *notification = new KNotification(QStringLiteral("distupgrade-notification"), KNotification::Persistent | KNotification::DefaultEvent); + updateStatusNotifier(); + + if (!notifyAboutUpdates()) { + return; + } + + KNotification *notification = new KNotification(QStringLiteral("DistUpgrade"), KNotification::Persistent); notification->setIconName(QStringLiteral("system-software-update")); notification->setActions(QStringList{i18nc("@action:button", "Upgrade")}); notification->setTitle(i18n("Upgrade available")); - notification->setText(i18n("New version: %1", action->description())); + notification->setText(i18n("%1 is now available.", action->description())); + notification->setComponentName(QStringLiteral("discoverabstractnotifier")); + connect(action, &UpgradeAction::showDiscoverUpdates, this, [this, notification]() { + showDiscoverUpdates(notification->xdgActivationToken()); + }); connect(notification, &KNotification::action1Activated, this, [action]() { action->trigger(); }); -- 2.41.0 From 536fc0a904313483a4ca852c9283b32b1f33e714 Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Sat, 22 Jul 2023 11:57:56 +0200 Subject: [PATCH 08/16] notifier: Add internationalization context to distro upgrade notification --- notifier/DiscoverNotifier.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notifier/DiscoverNotifier.cpp b/notifier/DiscoverNotifier.cpp index 70d29046c..32811c371 100644 --- a/notifier/DiscoverNotifier.cpp +++ b/notifier/DiscoverNotifier.cpp @@ -347,7 +347,7 @@ void DiscoverNotifier::foundUpgradeAction(UpgradeAction *action) notification->setIconName(QStringLiteral("system-software-update")); notification->setActions(QStringList{i18nc("@action:button", "Upgrade")}); notification->setTitle(i18n("Upgrade available")); - notification->setText(i18n("%1 is now available.", action->description())); + notification->setText(i18nc("A new distro release (name and version) is available for upgrade", "%1 is now available.", action->description())); notification->setComponentName(QStringLiteral("discoverabstractnotifier")); connect(action, &UpgradeAction::showDiscoverUpdates, this, [this, notification]() { -- 2.41.0 From 9718217d67f556f55c87e3a3a8762a0512b3655d Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Sat, 22 Jul 2023 17:16:16 +0200 Subject: [PATCH 09/16] pk: Reset distro upgrade status when refreshing We might find some normal updates instead, or a different distro version. Also, this this fixes the issue that when refreshing we wouldn't show the distro upgrade banner, because a previous distro upgrade was already set. --- .../backends/PackageKitBackend/PackageKitBackend.cpp | 1 + .../backends/PackageKitBackend/PackageKitUpdater.cpp | 11 +++++++++++ .../backends/PackageKitBackend/PackageKitUpdater.h | 1 + 3 files changed, 13 insertions(+) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 58fe44de6..73d2d2ee3 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -534,6 +534,7 @@ void PackageKitBackend::checkForUpdates() if (!m_refresher) { acquireFetching(true); + m_updater->clearDistroUpgrade(); m_refresher = PackageKit::Daemon::refreshCache(false); connect(m_refresher.data(), &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError); diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index c5c7e3755..18e275bb0 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -284,6 +284,12 @@ public: m_distroUpgrade = release; } + void clearDistroUpgrade() + { + m_distroUpgrade = std::nullopt; + Q_EMIT m_backend->inlineMessageChanged({}); + } + bool isDistroUpgrade() const { return m_distroUpgrade.has_value(); @@ -486,6 +492,11 @@ void PackageKitUpdater::setDistroUpgrade(const AppStream::Release &release) m_upgrade->setDistroUpgrade(release); } +void PackageKitUpdater::clearDistroUpgrade() +{ + m_upgrade->clearDistroUpgrade(); +} + bool PackageKitUpdater::isDistroUpgrade() const { return m_upgrade->isDistroUpgrade(); diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h index 4b75a472d..819917632 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.h @@ -47,6 +47,7 @@ public: void proceed() override; void setOfflineUpdates(bool use) override; void setDistroUpgrade(const AppStream::Release &release); + void clearDistroUpgrade(); bool isDistroUpgrade() const; public Q_SLOTS: -- 2.41.0 From a86ef71c2f3c1b1f7dbe6864d886d22f27b725fd Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Sun, 16 Jul 2023 19:51:13 +0200 Subject: [PATCH 10/16] appstream: Allow pre-release distro upgrades --- libdiscover/CMakeLists.txt | 2 +- libdiscover/appstream/AppStreamIntegration.cpp | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/libdiscover/CMakeLists.txt b/libdiscover/CMakeLists.txt index 549de813e..cd99fa53e 100644 --- a/libdiscover/CMakeLists.txt +++ b/libdiscover/CMakeLists.txt @@ -10,7 +10,7 @@ if (TARGET AppStreamQt) add_library(DiscoverAppStreamIntegration STATIC appstream/AppStreamIntegration.cpp ) - target_link_libraries(DiscoverAppStreamIntegration KF5::CoreAddons AppStreamQt) + target_link_libraries(DiscoverAppStreamIntegration KF5::CoreAddons KF5::ConfigCore AppStreamQt) set_property(TARGET DiscoverAppStreamIntegration PROPERTY POSITION_INDEPENDENT_CODE ON) endif() diff --git a/libdiscover/appstream/AppStreamIntegration.cpp b/libdiscover/appstream/AppStreamIntegration.cpp index 0852c7560..7029cab5c 100644 --- a/libdiscover/appstream/AppStreamIntegration.cpp +++ b/libdiscover/appstream/AppStreamIntegration.cpp @@ -8,6 +8,8 @@ #include <AppStreamQt/utils.h> #include <AppStreamQt/version.h> +#include <KConfigGroup> +#include <KSharedConfig> #include <QDebug> AppStreamIntegration *AppStreamIntegration::global() @@ -31,13 +33,16 @@ std::optional<AppStream::Release> AppStreamIntegration::getDistroUpgrade(AppStre return std::nullopt; } + KConfigGroup settings(KSharedConfig::openConfig(QStringLiteral("discoverrc")), "DistroUpgrade"); + bool allowPreRelease = settings.readEntry<bool>("AllowPreRelease", false); + QString currentVersion = osRelease()->versionId(); std::optional<AppStream::Release> nextRelease; for (const AppStream::Component &dc : distroComponents) { const auto releases = dc.releases(); for (const auto &r : releases) { - // Only look at stable releases - if (r.kind() != AppStream::Release::KindStable) { + // Only look at stable releases unless requested + if (!allowPreRelease && r.kind() != AppStream::Release::KindStable) { continue; } -- 2.41.0 From 8aa886b1a56706cb7dae695705e73e28a18b5a9a Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Tue, 22 Aug 2023 15:16:44 +0200 Subject: [PATCH 11/16] pk: Retire GetDistroUpgrades support GetDistroUpgrades is being retired in favour of discovering new distro versions through appstream metadata --- .../PackageKitBackend/PackageKitNotifier.cpp | 18 +++--------------- .../PackageKitBackend/PackageKitNotifier.h | 4 +--- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp index ca3afb51e..6aadbe9cd 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.cpp @@ -265,17 +265,7 @@ bool PackageKitNotifier::hasSecurityUpdates() return m_securityUpdates > 0; } -void PackageKitNotifier::onDistroUpgrade(PackageKit::Transaction::DistroUpgrade /*type*/, const QString &name, const QString &description) -{ - m_hasDistUpgrade = true; - auto a = new UpgradeAction(name, description, this); - connect(a, &UpgradeAction::triggered, this, [](const QString &name) { - PackageKit::Daemon::upgradeSystem(name, PackageKit::Transaction::UpgradeKindDefault); - }); - Q_EMIT foundUpgradeAction(a); -} - -void PackageKitNotifier::fallbackCheckDistroUpgrade() +void PackageKitNotifier::checkDistroUpgrade() { auto nextRelease = AppStreamIntegration::global()->getDistroUpgrade(m_appdata.get()); if (nextRelease) { @@ -308,10 +298,8 @@ void PackageKitNotifier::refreshDatabase() connect(m_refresher.data(), &PackageKit::Transaction::finished, this, &PackageKitNotifier::recheckSystemUpdateNeeded); } - if (!m_distUpgrades && (PackageKit::Daemon::roles() & PackageKit::Transaction::RoleUpgradeSystem)) { - m_distUpgrades = PackageKit::Daemon::getDistroUpgrades(); - connect(m_distUpgrades, &PackageKit::Transaction::distroUpgrade, this, &PackageKitNotifier::onDistroUpgrade); - connect(m_distUpgrades, &PackageKit::Transaction::errorCode, this, &PackageKitNotifier::fallbackCheckDistroUpgrade); + if (PackageKit::Daemon::roles() & PackageKit::Transaction::RoleUpgradeSystem) { + checkDistroUpgrade(); } } diff --git a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h index 43ff904cf..10bd3d194 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitNotifier.h @@ -32,14 +32,13 @@ public: { return m_needsReboot; } - void fallbackCheckDistroUpgrade(); + void checkDistroUpgrade(); private Q_SLOTS: void package(PackageKit::Transaction::Info info, const QString &packageID, const QString &summary); void finished(PackageKit::Transaction::Exit exit, uint); void onRequireRestart(PackageKit::Transaction::Restart type, const QString &packageID); void transactionListChanged(const QStringList &tids); - void onDistroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString &name, const QString &description); private: void nowNeedsReboot(); @@ -53,7 +52,6 @@ private: uint m_normalUpdates; bool m_hasDistUpgrade; QPointer<PackageKit::Transaction> m_refresher; - QPointer<PackageKit::Transaction> m_distUpgrades; QTimer *m_recheckTimer; QHash<QString, PackageKit::Transaction *> m_transactions; -- 2.41.0 From 5ab6265de783295455ff408118fcdf57741b9a7a Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Sat, 26 Aug 2023 00:00:47 +0200 Subject: [PATCH 12/16] pk: Handle distro-upgrade download cancel or failure --- .../backends/PackageKitBackend/PackageKitUpdater.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index 18e275bb0..f478f9d1e 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -587,11 +587,15 @@ void PackageKitUpdater::finished(PackageKit::Transaction::Exit exit, uint /*time return; } - // Fetching updates now would clear the prepared-upgrade if (!m_toUpgrade.contains(m_upgrade) || !m_upgrade->isDistroUpgrade()) { + // If the distro-upgrade was prepared successfully, fetching updates now would invalidate it. + // If the distro-upgrade failed, fetching updates now would find nothing and we would propose to reboot. setProgressing(false); m_backend->fetchUpdates(); fetchLastUpdateTime(); + } else if (exit != PackageKit::Transaction::ExitSuccess) { + Q_EMIT resourceProgressed(m_upgrade, 0, None); + setProgressing(false); } if (useOfflineUpdates() && exit == PackageKit::Transaction::ExitSuccess) { -- 2.41.0 From 0230128ebaf1a4f0c8289a076844e2c5bf30675c Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Mon, 28 Aug 2023 16:50:31 +0200 Subject: [PATCH 13/16] pk: Set cache-age for distro-upgrade transaction The behaviour of different backends with respect to cache expiry is not unique with the default cache-age setting. In Fedora by default the cache is never expired. Instead, a patch downstream is implemented to force refresh the cache. However, that leaves untouched the cache of the non-current distro releases, as used by UpgradeSystem. It is thus important that we explicitly specify a cache-age hint to unequivocally expire the cache after a while. --- .../backends/PackageKitBackend/PackageKitBackend.cpp | 4 ++-- libdiscover/backends/PackageKitBackend/PackageKitBackend.h | 6 ++++++ .../backends/PackageKitBackend/PackageKitUpdater.cpp | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index 73d2d2ee3..dd190eb83 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -192,8 +192,8 @@ PackageKitBackend::PackageKitBackend(QObject *parent) }, this); - PackageKit::Daemon::global()->setHints(QStringList() << QStringLiteral("interactive=true") - << QStringLiteral("locale=%1").arg(qEnvironmentVariable("LANG"))); + m_globalHints = QStringList() << QStringLiteral("interactive=true") << QStringLiteral("locale=%1").arg(qEnvironmentVariable("LANG")); + PackageKit::Daemon::global()->setHints(m_globalHints); } PackageKitBackend::~PackageKitBackend() diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h index 5dc7fa235..14d67193c 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.h +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.h @@ -126,6 +126,11 @@ public: m_updatesPackageId.clear(); } + QStringList globalHints() + { + return m_globalHints; + } + public Q_SLOTS: void reloadPackageList(); void transactionError(PackageKit::Transaction::Error, const QString &message); @@ -184,4 +189,5 @@ private: QPointer<PackageKit::Transaction> m_getUpdatesTransaction; QThreadPool m_threadPool; QPointer<PKResolveTransaction> m_resolveTransaction; + QStringList m_globalHints; }; diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index f478f9d1e..c37d16880 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -374,6 +374,7 @@ void PackageKitUpdater::setupTransaction(PackageKit::Transaction::TransactionFla if (m_toUpgrade.contains(m_upgrade) && m_upgrade->isDistroUpgrade()) { const QString& upgradeVersion = m_upgrade->getDistroUpgrade().version(); m_transaction = PackageKit::Daemon::upgradeSystem(upgradeVersion, PackageKit::Transaction::UpgradeKind::UpgradeKindComplete, flags); + m_transaction->setHints(m_backend->globalHints() << QStringLiteral("cache-age=86400" /* 24*60*60 */)); } else { auto pkgs = involvedPackages(m_toUpgrade).values(); pkgs.sort(); -- 2.41.0 From 90dfdf5553e28800a19de453caf520677fa5b214 Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Wed, 30 Aug 2023 14:51:56 +0200 Subject: [PATCH 14/16] pk: Set cache-age also when fetching the initial distro-upgrade metadata --- libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index dd190eb83..c5d174f7c 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -922,6 +922,7 @@ void PackageKitBackend::foundNewMajorVersion(const AppStream::Release &release) m_updatesPackageId.clear(); m_updater->setProgressing(true); PackageKit::Transaction *transaction = PackageKit::Daemon::upgradeSystem(upgradeVersion, PackageKit::Transaction::UpgradeKind::UpgradeKindComplete, PackageKit::Transaction::TransactionFlagSimulate); + transaction->setHints(globalHints() << QStringLiteral("cache-age=86400" /* 24*60*60 */)); connect(transaction, &PackageKit::Transaction::package, this, &PackageKitBackend::addPackageToUpdate); connect(transaction, &PackageKit::Transaction::percentageChanged, this, &PackageKitBackend::fetchingUpdatesProgressChanged); connect(transaction, &PackageKit::Transaction::errorCode, this, &PackageKitBackend::transactionError); -- 2.41.0 From 2337b1411af9930386740c85c19e12c68f48dbcd Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Wed, 30 Aug 2023 21:41:18 +0200 Subject: [PATCH 15/16] Allow setting needsReboot to false --- libdiscover/backends/FwupdBackend/FwupdTransaction.cpp | 2 +- .../backends/PackageKitBackend/PackageKitBackend.cpp | 4 +++- .../backends/PackageKitBackend/PackageKitUpdater.cpp | 4 ++-- .../backends/RpmOstreeBackend/RpmOstreeBackend.cpp | 10 +++++----- libdiscover/backends/SteamOSBackend/SteamOSBackend.cpp | 2 +- libdiscover/resources/AbstractBackendUpdater.cpp | 6 +++--- libdiscover/resources/AbstractBackendUpdater.h | 2 +- 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp b/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp index cd7d6cb7c..d9d114fb3 100644 --- a/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp +++ b/libdiscover/backends/FwupdBackend/FwupdTransaction.cpp @@ -122,7 +122,7 @@ void FwupdTransaction::finishTransaction() } m_app->setState(newState); if (m_app->needsReboot()) { - m_app->backend()->backendUpdater()->enableNeedsReboot(); + m_app->backend()->backendUpdater()->setNeedsReboot(true); } setStatus(DoneStatus); deleteLater(); diff --git a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp index c5d174f7c..d86d8bec8 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitBackend.cpp @@ -161,7 +161,9 @@ PackageKitBackend::PackageKitBackend(QObject *parent) }); }); - connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, m_updater, &PackageKitUpdater::enableNeedsReboot); + connect(PackageKit::Daemon::global(), &PackageKit::Daemon::restartScheduled, this, [this] { + m_updater->setNeedsReboot(true); + }); connect(PackageKit::Daemon::global(), &PackageKit::Daemon::isRunningChanged, this, &PackageKitBackend::checkDaemonRunning); connect(m_reviews.data(), &OdrsReviewsBackend::ratingsReady, this, [this] { m_reviews->emitRatingFetched(this, kTransform<QList<AbstractResource *>>(m_packages.packages, [](AbstractResource *r) { diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index c37d16880..4770b1c2c 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -332,7 +332,7 @@ void PackageKitUpdater::prepare() if (auto offline = PackageKit::Daemon::global()->offline(); offline->updateTriggered() || offline->upgradeTriggered()) { m_toUpgrade.clear(); m_allUpgradeable.clear(); - enableNeedsReboot(); + setNeedsReboot(true); return; } @@ -511,7 +511,7 @@ void PackageKitUpdater::start() setProgressing(true); if (useOfflineUpdates()) { - enableNeedsReboot(); + setNeedsReboot(true); } } diff --git a/libdiscover/backends/RpmOstreeBackend/RpmOstreeBackend.cpp b/libdiscover/backends/RpmOstreeBackend/RpmOstreeBackend.cpp index 6e1528be4..08d757556 100644 --- a/libdiscover/backends/RpmOstreeBackend/RpmOstreeBackend.cpp +++ b/libdiscover/backends/RpmOstreeBackend/RpmOstreeBackend.cpp @@ -185,7 +185,7 @@ void RpmOstreeBackend::refreshDeployments() m_currentlyBootedDeployment = deployment; } else if (deployment->isPending()) { // Signal that we have a pending update - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); } } @@ -277,7 +277,7 @@ void RpmOstreeBackend::checkForUpdates() if (deployment->version() == newVersion) { qInfo() << "rpm-ostree-backend: Found existing deployment for new version. Skipping."; // Let the user know that the update is pending a reboot - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); if (m_currentlyBootedDeployment->getNextMajorVersion().isEmpty()) { Q_EMIT inlineMessageChanged(nullptr); } else { @@ -420,7 +420,7 @@ void RpmOstreeBackend::foundNewMajorVersion(const QString &newMajorVersion) } if (deploymentVersion == newMajorVersion) { qInfo() << "rpm-ostree-backend: Found existing deployment for new major version"; - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); Q_EMIT inlineMessageChanged(nullptr); return; } @@ -434,7 +434,7 @@ void RpmOstreeBackend::foundNewMajorVersion(const QString &newMajorVersion) RpmOstreeResource *deployment = iterator.next(); if ((deployment->version() == newVersion) || deployment->isPending()) { qInfo() << "rpm-ostree-backend: Found pending or updated deployment for current version"; - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); Q_EMIT inlineMessageChanged(m_rebootBeforeRebaseMessage); return; } @@ -446,7 +446,7 @@ void RpmOstreeBackend::foundNewMajorVersion(const QString &newMajorVersion) // version. if (m_currentlyBootedDeployment->state() == AbstractResource::Upgradeable) { qInfo() << "rpm-ostree-backend: Found pending update for current version"; - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); Q_EMIT inlineMessageChanged(m_rebootBeforeRebaseMessage); return; } diff --git a/libdiscover/backends/SteamOSBackend/SteamOSBackend.cpp b/libdiscover/backends/SteamOSBackend/SteamOSBackend.cpp index 4a9f90a30..8626becbc 100644 --- a/libdiscover/backends/SteamOSBackend/SteamOSBackend.cpp +++ b/libdiscover/backends/SteamOSBackend/SteamOSBackend.cpp @@ -95,7 +95,7 @@ void SteamOSBackend::hasUpdateChanged(bool hasUpdate) void SteamOSBackend::needRebootChanged() { // Tell gui we need to reboot - m_updater->enableNeedsReboot(); + m_updater->setNeedsReboot(true); } void SteamOSBackend::acquireFetching(bool f) diff --git a/libdiscover/resources/AbstractBackendUpdater.cpp b/libdiscover/resources/AbstractBackendUpdater.cpp index 7ae9888da..b0bea1038 100644 --- a/libdiscover/resources/AbstractBackendUpdater.cpp +++ b/libdiscover/resources/AbstractBackendUpdater.cpp @@ -26,12 +26,12 @@ void AbstractBackendUpdater::fetchChangelog() const } } -void AbstractBackendUpdater::enableNeedsReboot() +void AbstractBackendUpdater::setNeedsReboot(bool enabled) { - if (m_needsReboot) + if (m_needsReboot == enabled) return; - m_needsReboot = true; + m_needsReboot = enabled; Q_EMIT needsRebootChanged(); } diff --git a/libdiscover/resources/AbstractBackendUpdater.h b/libdiscover/resources/AbstractBackendUpdater.h index 9ab01759a..1e469f815 100644 --- a/libdiscover/resources/AbstractBackendUpdater.h +++ b/libdiscover/resources/AbstractBackendUpdater.h @@ -123,7 +123,7 @@ public: */ virtual quint64 downloadSpeed() const = 0; - void enableNeedsReboot(); + void setNeedsReboot(bool enabled); void enableReadyToReboot(); bool isReadyToReboot() const; -- 2.41.0 From 1038b0a9505a0ce548f6864647c471df940540de Mon Sep 17 00:00:00 2001 From: Alessandro Astone <ales.astone@gmail.com> Date: Wed, 30 Aug 2023 21:44:07 +0200 Subject: [PATCH 16/16] pk: Reset needsReboot to false when distro-upgrade fails If the user refreshes the updates after aborting a distro-upgrade, discover would have proposed to reboot. --- libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp index 4770b1c2c..940b0a151 100644 --- a/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp +++ b/libdiscover/backends/PackageKitBackend/PackageKitUpdater.cpp @@ -596,6 +596,7 @@ void PackageKitUpdater::finished(PackageKit::Transaction::Exit exit, uint /*time fetchLastUpdateTime(); } else if (exit != PackageKit::Transaction::ExitSuccess) { Q_EMIT resourceProgressed(m_upgrade, 0, None); + setNeedsReboot(false); setProgressing(false); } @@ -606,6 +607,7 @@ void PackageKitUpdater::finished(PackageKit::Transaction::Exit exit, uint /*time reply.waitForFinished(); if (reply.isError()) { Q_EMIT resourceProgressed(m_upgrade, 0, None); + setNeedsReboot(false); setProgressing(false); Q_EMIT passiveMessage(reply.error().message()); return; -- 2.41.0
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.
浙ICP备2022010568号-2