screenbrightnessplugin: Fix behaviour if dbus service is not initialized followup

Fix abfe419b3b
This commit is contained in:
Devin Lin 2024-11-10 22:56:35 -08:00
parent abfe419b3b
commit fdf2ad87f6
2 changed files with 23 additions and 22 deletions

View file

@ -20,7 +20,6 @@ target_link_libraries(screenbrightnessplugin PRIVATE
KF6::ConfigGui KF6::ConfigGui
KF6::I18n KF6::I18n
KF6::Screen KF6::Screen
QCoro::DBus
) )
ecm_finalize_qml_module(screenbrightnessplugin) ecm_finalize_qml_module(screenbrightnessplugin)

View file

@ -66,32 +66,34 @@ bool ScreenBrightnessUtil::brightnessAvailable() const
void ScreenBrightnessUtil::fetchBrightness() void ScreenBrightnessUtil::fetchBrightness()
{ {
QDBusPendingReply<int> pendingReply = m_brightnessInterface->brightness(); QDBusPendingReply<int> reply = m_brightnessInterface->brightness();
const auto reply = co_await pendingReply; QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<int> reply = *watcher;
if (reply.isError()) { if (reply.isError()) {
qWarning() << "Getting brightness failed:" << reply.error().name() << reply.error().message(); qWarning() << "Getting brightness failed:" << reply.error().name() << reply.error().message();
return; } else if (m_brightness != reply.value()) {
}
if (m_brightness != reply.value()) {
m_brightness = reply.value(); m_brightness = reply.value();
Q_EMIT brightnessChanged(); Q_EMIT brightnessChanged();
} }
watcher->deleteLater();
});
} }
void ScreenBrightnessUtil::fetchMaxBrightness() void ScreenBrightnessUtil::fetchMaxBrightness()
{ {
QDBusPendingReply<int> reply = m_brightnessInterface->brightnessMax(); QDBusPendingReply<int> reply = m_brightnessInterface->brightnessMax();
const auto reply = co_await pendingReply; QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<int> reply = *watcher;
if (reply.isError()) { if (reply.isError()) {
qWarning() << "Getting max brightness failed:" << reply.error().name() << reply.error().message(); qWarning() << "Getting max brightness failed:" << reply.error().name() << reply.error().message();
return; } else if (m_maxBrightness != reply.value()) {
}
if (m_maxBrightness != reply.value()) {
m_maxBrightness = reply.value(); m_maxBrightness = reply.value();
Q_EMIT maxBrightnessChanged(); Q_EMIT maxBrightnessChanged();
} }
watcher->deleteLater();
});
} }