From c52a5927e5ca74403b4b861f3ee8549f4ef55682 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Tue, 19 Apr 2022 22:35:23 +0200 Subject: [PATCH] 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`. --- .../platform/linux/specific_linux.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 277e11aa13..dd0e5966e2 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -382,12 +382,6 @@ QString GetIconName() { std::optional 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 IsDarkMode() { const Glib::VariantBase &value) { if (group == "org.freedesktop.appearance" && key == "color-scheme") { - Setter(); + try { + const auto ivalue = base::Platform::GlibVariantCast(value); + + crl::on_main([=] { + Core::App().settings().setSystemDarkMode(ivalue == 1); + }); + } catch (...) { + } } }); @@ -410,10 +411,7 @@ std::optional IsDarkMode() { if (result.has_value()) { const auto value = base::Platform::GlibVariantCast(*result); - if (value == 1) { - return true; - } - return false; + return value == 1; } } catch (...) { }