From 0f86968afde2ef8543577444c416ddb5311a8dc8 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Tue, 19 Sep 2023 15:25:30 +0400 Subject: [PATCH] Use ServerInformation without std::optional --- .../linux/notifications_manager_linux.cpp | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp index 35aa77a00..ae289833a 100644 --- a/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/notifications_manager_linux.cpp @@ -50,7 +50,7 @@ struct ServerInformation { }; bool ServiceRegistered = false; -std::optional CurrentServerInformation; +ServerInformation CurrentServerInformation; std::vector CurrentCapabilities; void Noexcept(Fn callback, Fn failed = nullptr) noexcept { @@ -177,8 +177,7 @@ bool GetServiceRegistered() { return false; } -void GetServerInformation( - Fn &)> callback) { +void GetServerInformation(Fn callback) { Noexcept([&] { const auto connection = Gio::DBus::Connection::get_sync( Gio::DBus::BusType::SESSION); @@ -218,13 +217,13 @@ void GetServerInformation( QString::fromStdString(specVersion)), }); }, [&] { - callback(std::nullopt); + callback({}); }); }); }, kService); }, [&] { - callback(std::nullopt); + callback({}); }); } @@ -294,10 +293,6 @@ void GetInhibited(Fn callback) { }); } -ServerInformation CurrentServerInformationValue() { - return CurrentServerInformation.value_or(ServerInformation{}); -} - Glib::ustring GetImageKey(const QVersionNumber &specificationVersion) { const auto normalizedVersion = specificationVersion.normalized(); @@ -509,7 +504,7 @@ bool NotificationData::init( }); }); - _imageKey = GetImageKey(CurrentServerInformationValue().specVersion); + _imageKey = GetImageKey(CurrentServerInformation.specVersion); if (ranges::contains(capabilities, "body-markup")) { _title = title.toStdString(); @@ -867,14 +862,13 @@ void Create(Window::Notifications::System *system) { ServiceRegistered = GetServiceRegistered(); if (!ServiceRegistered) { - CurrentServerInformation = std::nullopt; + CurrentServerInformation = {}; CurrentCapabilities = {}; managerSetter(); return; } - GetServerInformation([=]( - const std::optional &result) { + GetServerInformation([=](const ServerInformation &result) { CurrentServerInformation = result; oneReady(); }); @@ -927,18 +921,24 @@ Manager::Private::Private(not_null manager) const auto &serverInformation = CurrentServerInformation; const auto &capabilities = CurrentCapabilities; - if (serverInformation.has_value()) { + if (!serverInformation.name.empty()) { LOG(("Notification daemon product name: %1") - .arg(serverInformation->name.c_str())); + .arg(serverInformation.name.c_str())); + } + if (!serverInformation.vendor.empty()) { LOG(("Notification daemon vendor name: %1") - .arg(serverInformation->vendor.c_str())); + .arg(serverInformation.vendor.c_str())); + } + if (!serverInformation.version.isNull()) { LOG(("Notification daemon version: %1") - .arg(serverInformation->version.toString())); + .arg(serverInformation.version.toString())); + } + if (!serverInformation.specVersion.isNull()) { LOG(("Notification daemon specification version: %1") - .arg(serverInformation->specVersion.toString())); + .arg(serverInformation.specVersion.toString())); } if (!capabilities.empty()) {