Commit 45cea4fc authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

Delay the reboot notification after the update transaction has finished

parent 4a072216
......@@ -203,6 +203,9 @@ void PackageKitNotifier::transactionListChanged(const QStringList& tids)
auto t = new PackageKit::Transaction(QDBusObjectPath(tid));
connect(t, &PackageKit::Transaction::requireRestart, this, &PackageKitNotifier::onRequireRestart);
connect(t, &PackageKit::Transaction::finished, this, [this, t](){
auto restart = t->property("requireRestart");
if (!restart.isNull())
requireRestartNotification(PackageKit::Transaction::Restart(restart.toInt()));
m_transactions.remove(t->tid().path());
t->deleteLater();
});
......@@ -212,30 +215,37 @@ void PackageKitNotifier::transactionListChanged(const QStringList& tids)
void PackageKitNotifier::onRequireRestart(PackageKit::Transaction::Restart type, const QString &packageID)
{
if (type == PackageKit::Transaction::RestartSystem || type == PackageKit::Transaction::RestartSession) {
KNotification *notification = new KNotification(QLatin1String("notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
if (type == PackageKit::Transaction::RestartSystem) {
notification->setActions(QStringList{QLatin1String("Restart")});
notification->setTitle(i18n("Restart is required"));
notification->setText(i18n("The computer will have to be restarted after the update for the changes to take effect."));
} else {
notification->setActions(QStringList{QLatin1String("Logout")});
notification->setTitle(i18n("Session restart is required"));
notification->setText(i18n("You will need to log out and back in after the update for the changes to take effect."));
}
PackageKit::Transaction* t = qobject_cast<PackageKit::Transaction*>(sender());
t->setProperty("requireRestart", qMax<int>(t->property("requireRestart").toInt(), type));
qDebug() << "RESTART" << type << "is required for package" << packageID;
}
connect(notification, &KNotification::action1Activated, this, [type] () {
QDBusInterface interface(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QStringLiteral("org.kde.KSMServerInterface"), QDBusConnection::sessionBus());
if (type == PackageKit::Transaction::RestartSystem) {
interface.asyncCall(QStringLiteral("logout"), 0, 1, 2); // Options: do not ask again | reboot | force
} else {
interface.asyncCall(QStringLiteral("logout"), 0, 0, 2); // Options: do not ask again | logout | force
}
});
void PackageKitNotifier::requireRestartNotification(PackageKit::Transaction::Restart type)
{
if (type < PackageKit::Transaction::RestartSession) {
return;
}
notification->sendEvent();
KNotification *notification = new KNotification(QLatin1String("notification"), KNotification::Persistent | KNotification::DefaultEvent);
notification->setIconName(QStringLiteral("system-software-update"));
if (type == PackageKit::Transaction::RestartSystem || type == PackageKit::Transaction::RestartSecuritySystem) {
notification->setActions(QStringList{QLatin1String("Restart")});
notification->setTitle(i18n("Restart is required"));
notification->setText(i18n("The system needs to be restarted for the updates to take effect."));
} else {
notification->setActions(QStringList{QLatin1String("Logout")});
notification->setTitle(i18n("Session restart is required"));
notification->setText(i18n("You will need to log out and back in for the update to take effect."));
}
qDebug() << "RESTART" << type << "is required for package" << packageID;
connect(notification, &KNotification::action1Activated, this, [type] () {
QDBusInterface interface(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QStringLiteral("org.kde.KSMServerInterface"), QDBusConnection::sessionBus());
if (type == PackageKit::Transaction::RestartSystem) {
interface.asyncCall(QStringLiteral("logout"), 0, 1, 2); // Options: do not ask again | reboot | force
} else {
interface.asyncCall(QStringLiteral("logout"), 0, 0, 2); // Options: do not ask again | logout | force
}
});
notification->sendEvent();
}
......@@ -51,6 +51,7 @@ private Q_SLOTS:
void onDistroUpgrade(PackageKit::Transaction::DistroUpgrade type, const QString &name, const QString &description);
private:
void requireRestartNotification(PackageKit::Transaction::Restart type);
QProcess* checkAptVariable(const QString &aptconfig, const QLatin1String& varname, std::function<void(const QStringRef& val)> func);
uint m_securityUpdates;
......
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