Use ServerInformation without std::optional

This commit is contained in:
Ilya Fedin 2023-09-19 15:25:30 +04:00 committed by John Preston
parent 90f52d80d7
commit 0f86968afd
1 changed files with 18 additions and 18 deletions

View File

@ -50,7 +50,7 @@ struct ServerInformation {
};
bool ServiceRegistered = false;
std::optional<ServerInformation> CurrentServerInformation;
ServerInformation CurrentServerInformation;
std::vector<Glib::ustring> CurrentCapabilities;
void Noexcept(Fn<void()> callback, Fn<void()> failed = nullptr) noexcept {
@ -177,8 +177,7 @@ bool GetServiceRegistered() {
return false;
}
void GetServerInformation(
Fn<void(const std::optional<ServerInformation> &)> callback) {
void GetServerInformation(Fn<void(const ServerInformation &)> 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<void(bool)> 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<ServerInformation> &result) {
GetServerInformation([=](const ServerInformation &result) {
CurrentServerInformation = result;
oneReady();
});
@ -927,18 +921,24 @@ Manager::Private::Private(not_null<Manager*> 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()) {