Avoid a second query for the current color-scheme

Telegram listens for a signal that indicates when the color-scheme
changes. The signal itself includes the new value, but Telegram
currently queries for the value immediately after getting the signal.
This second round-trip is unnecessary, since the signal itself contains
the same information.

This changeset avoids this follow-up query, and drops the now-unused
`Setter`.
This commit is contained in:
Hugo Osvaldo Barrera 2022-04-19 22:35:23 +02:00 committed by John Preston
parent edcfac8da3
commit c52a5927e5

View File

@ -382,12 +382,6 @@ QString GetIconName() {
std::optional<bool> IsDarkMode() {
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
[[maybe_unused]] static const auto Inited = [] {
static const auto Setter = [] {
crl::on_main([] {
Core::App().settings().setSystemDarkMode(IsDarkMode());
});
};
using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
static const XDPSettingWatcher Watcher(
[=](
@ -396,7 +390,14 @@ std::optional<bool> IsDarkMode() {
const Glib::VariantBase &value) {
if (group == "org.freedesktop.appearance"
&& key == "color-scheme") {
Setter();
try {
const auto ivalue = base::Platform::GlibVariantCast<uint>(value);
crl::on_main([=] {
Core::App().settings().setSystemDarkMode(ivalue == 1);
});
} catch (...) {
}
}
});
@ -410,10 +411,7 @@ std::optional<bool> IsDarkMode() {
if (result.has_value()) {
const auto value = base::Platform::GlibVariantCast<uint>(*result);
if (value == 1) {
return true;
}
return false;
return value == 1;
}
} catch (...) {
}