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:
		
							parent
							
								
									edcfac8da3
								
							
						
					
					
						commit
						c52a5927e5
					
				
					 1 changed files with 9 additions and 11 deletions
				
			
		| 
						 | 
					@ -382,12 +382,6 @@ QString GetIconName() {
 | 
				
			||||||
std::optional<bool> IsDarkMode() {
 | 
					std::optional<bool> IsDarkMode() {
 | 
				
			||||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
 | 
					#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
 | 
				
			||||||
	[[maybe_unused]] static const auto Inited = [] {
 | 
						[[maybe_unused]] static const auto Inited = [] {
 | 
				
			||||||
		static const auto Setter = [] {
 | 
					 | 
				
			||||||
			crl::on_main([] {
 | 
					 | 
				
			||||||
				Core::App().settings().setSystemDarkMode(IsDarkMode());
 | 
					 | 
				
			||||||
			});
 | 
					 | 
				
			||||||
		};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
 | 
							using XDPSettingWatcher = base::Platform::XDP::SettingWatcher;
 | 
				
			||||||
		static const XDPSettingWatcher Watcher(
 | 
							static const XDPSettingWatcher Watcher(
 | 
				
			||||||
			[=](
 | 
								[=](
 | 
				
			||||||
| 
						 | 
					@ -396,7 +390,14 @@ std::optional<bool> IsDarkMode() {
 | 
				
			||||||
				const Glib::VariantBase &value) {
 | 
									const Glib::VariantBase &value) {
 | 
				
			||||||
				if (group == "org.freedesktop.appearance"
 | 
									if (group == "org.freedesktop.appearance"
 | 
				
			||||||
					&& key == "color-scheme") {
 | 
										&& 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()) {
 | 
							if (result.has_value()) {
 | 
				
			||||||
			const auto value = base::Platform::GlibVariantCast<uint>(*result);
 | 
								const auto value = base::Platform::GlibVariantCast<uint>(*result);
 | 
				
			||||||
			if (value == 1) {
 | 
								return value == 1;
 | 
				
			||||||
				return true;
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			return false;
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} catch (...) {
 | 
						} catch (...) {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue