Commit 7b918b96 authored by Fabian Vogt's avatar Fabian Vogt
Browse files

notifier: Use KIdleTime properly

Use the ID returned by the timeout registration for deregistration and
trigger detection. This avoids conflicts with other users of kidletime.

(cherry picked from commit 9d358eeb)
parent db151e2a
......@@ -24,7 +24,9 @@ UnattendedUpdates::UnattendedUpdates(DiscoverNotifier *parent)
UnattendedUpdates::~UnattendedUpdates() noexcept
{
KIdleTime::instance()->removeAllIdleTimeouts();
if (m_idleTimeoutId.has_value()) {
KIdleTime::instance()->removeIdleTimeout(m_idleTimeoutId.value());
}
}
void UnattendedUpdates::checkNewState()
......@@ -39,24 +41,27 @@ void UnattendedUpdates::checkNewState()
return;
}
if (!KIdleTime::instance()->idleTimeouts().isEmpty()) {
qDebug() << "already waiting for an idle time";
return;
}
if (notifier->hasUpdates()) {
const bool hasUpdates = notifier->hasUpdates();
if (hasUpdates && !m_idleTimeoutId.has_value()) {
qDebug() << "waiting for an idle moment";
// If the system is untouched for 15 minutes, trigger the unattened update
KIdleTime::instance()->addIdleTimeout(int(std::chrono::milliseconds(15min).count()));
} else {
m_idleTimeoutId = KIdleTime::instance()->addIdleTimeout(int(std::chrono::milliseconds(15min).count()));
} else if (!hasUpdates && m_idleTimeoutId.has_value()) {
qDebug() << "nothing to do";
KIdleTime::instance()->removeAllIdleTimeouts();
KIdleTime::instance()->removeIdleTimeout(m_idleTimeoutId.value());
m_idleTimeoutId.reset();
}
}
void UnattendedUpdates::triggerUpdate()
void UnattendedUpdates::triggerUpdate(int timeoutId)
{
KIdleTime::instance()->removeAllIdleTimeouts();
if (!m_idleTimeoutId.has_value() || timeoutId != m_idleTimeoutId.value()) {
return;
}
KIdleTime::instance()->removeIdleTimeout(m_idleTimeoutId.value());
m_idleTimeoutId.reset();
DiscoverNotifier *notifier = static_cast<DiscoverNotifier *>(parent());
if (!notifier->hasUpdates() || notifier->isBusy()) {
return;
......
......@@ -6,6 +6,8 @@
#pragma once
#include <optional>
#include <QObject>
class DiscoverNotifier;
......@@ -19,5 +21,7 @@ public:
private:
void checkNewState();
void triggerUpdate();
void triggerUpdate(int timeoutId);
std::optional<int> m_idleTimeoutId;
};
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