Commit 50cbb53a authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Make sure pk updates don't go out of sync

Listen to all updates request transactions and update the values
accordingly.

BUG: 385754
parent 99b204af
......@@ -72,6 +72,11 @@ PackageKitNotifier::PackageKitNotifier(QObject* parent)
regularCheck->start();
QTimer::singleShot(3000, this, &PackageKitNotifier::checkOfflineUpdates);
m_recheckTimer = new QTimer(this);
m_recheckTimer->setInterval(200);
m_recheckTimer->setSingleShot(true);
connect(m_recheckTimer, &QTimer::timeout, this, &PackageKitNotifier::recheckSystemUpdate);
}
PackageKitNotifier::~PackageKitNotifier()
......@@ -121,16 +126,27 @@ void PackageKitNotifier::checkOfflineUpdates()
}
void PackageKitNotifier::recheckSystemUpdateNeeded()
{
m_recheckTimer->start();
}
void PackageKitNotifier::recheckSystemUpdate()
{
if (PackageKit::Daemon::global()->isRunning()) {
PackageKit::Transaction * trans = PackageKit::Daemon::getUpdates();
trans->setProperty("normalUpdates", 0);
trans->setProperty("securityUpdates", 0);
connect(trans, &PackageKit::Transaction::package, this, &PackageKitNotifier::package);
connect(trans, &PackageKit::Transaction::finished, this, &PackageKitNotifier::finished);
PackageKit::Daemon::getUpdates();
}
}
void PackageKitNotifier::setupGetUpdatesTransaction(PackageKit::Transaction* trans)
{
qDebug() << "using..." << trans << trans->tid().path();
trans->setProperty("normalUpdates", 0);
trans->setProperty("securityUpdates", 0);
connect(trans, &PackageKit::Transaction::package, this, &PackageKitNotifier::package);
connect(trans, &PackageKit::Transaction::finished, this, &PackageKitNotifier::finished);
}
void PackageKitNotifier::package(PackageKit::Transaction::Info info, const QString &/*packageID*/, const QString &/*summary*/)
{
PackageKit::Transaction * trans = qobject_cast<PackageKit::Transaction *>(sender());
......@@ -253,6 +269,12 @@ void PackageKitNotifier::transactionListChanged(const QStringList& tids)
continue;
auto t = new PackageKit::Transaction(QDBusObjectPath(tid));
connect(t, &PackageKit::Transaction::roleChanged, this, [this, t]() {
if (t->role() == PackageKit::Transaction::RoleGetUpdates) {
setupGetUpdatesTransaction(t);
}
});
connect(t, &PackageKit::Transaction::requireRestart, this, &PackageKitNotifier::onRequireRestart);
connect(t, &PackageKit::Transaction::finished, this, [this, t](){
auto restart = t->property("requireRestart");
......
......@@ -26,6 +26,7 @@
#include <PackageKit/Transaction>
#include <functional>
class QTimer;
class QProcess;
class PackageKitNotifier : public BackendNotifierModule
......@@ -51,14 +52,17 @@ private Q_SLOTS:
void onDistroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString &name, const QString &description);
private:
void recheckSystemUpdate();
void checkOfflineUpdates();
void requireRestartNotification(PackageKit::Transaction::Restart type);
void setupGetUpdatesTransaction(PackageKit::Transaction* transaction);
QProcess* checkAptVariable(const QString &aptconfig, const QLatin1String& varname, std::function<void(const QStringRef& val)> func);
uint m_securityUpdates;
uint m_normalUpdates;
QPointer<PackageKit::Transaction> m_refresher;
QPointer<PackageKit::Transaction> m_distUpgrades;
QTimer* m_recheckTimer;
QHash<QString, PackageKit::Transaction*> m_transactions;
};
......
Markdown is supported
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