Fix freeze in notifications settings when notification daemon is unavailable

This commit is contained in:
Ilya Fedin 2020-04-28 08:32:24 +04:00 committed by John Preston
parent 48743a7973
commit 46d4b03d49
1 changed files with 49 additions and 4 deletions

View File

@ -31,8 +31,51 @@ constexpr auto kObjectPath = "/org/freedesktop/Notifications"_cs;
constexpr auto kInterface = kService;
constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs;
bool NotificationsSupported = false;
bool InhibitedNotSupported = false;
void ComputeSupported(bool wait = false) {
const auto message = QDBusMessage::createMethodCall(
kService.utf16(),
kObjectPath.utf16(),
kInterface.utf16(),
qsl("GetServerInformation"));
auto async = QDBusConnection::sessionBus().asyncCall(message);
auto watcher = new QDBusPendingCallWatcher(async);
QObject::connect(
watcher,
&QDBusPendingCallWatcher::finished,
[=](QDBusPendingCallWatcher *call) {
QDBusPendingReply<QString, QString, QString, QString> reply = *call;
if (reply.isValid()) {
NotificationsSupported = true;
}
call->deleteLater();
});
if (wait) {
watcher->waitForFinished();
}
}
void GetSupported() {
static auto Checked = false;
if (Checked) {
return;
}
Checked = true;
if (Global::NativeNotifications()) {
ComputeSupported(true);
} else {
ComputeSupported();
}
}
std::vector<QString> ComputeServerInformation() {
std::vector<QString> serverInformation;
@ -427,20 +470,22 @@ bool SkipToast() {
bool Supported() {
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
static const auto Available = !GetServerInformation().empty();
return Available;
#else // !TDESKTOP_DISABLE_DBUS_INTEGRATION
return NotificationsSupported;
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
return false;
#endif // TDESKTOP_DISABLE_DBUS_INTEGRATION
}
std::unique_ptr<Window::Notifications::Manager> Create(
Window::Notifications::System *system) {
#ifndef TDESKTOP_DISABLE_DBUS_INTEGRATION
GetSupported();
if (Global::NativeNotifications() && Supported()) {
return std::make_unique<Manager>(system);
}
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
return nullptr;
}