@@ -9,9 +9,12 @@ use once_cell::sync::Lazy;
99use windows:: {
1010 core:: { s, w, BOOL , PCSTR , PSTR } ,
1111 Win32 :: {
12- Foundation :: { HANDLE , HMODULE , HWND , LPARAM , WPARAM } ,
12+ Foundation :: { ERROR_SUCCESS , HANDLE , HMODULE , HWND , LPARAM , WPARAM } ,
1313 Graphics :: Dwm :: { DwmSetWindowAttribute , DWMWINDOWATTRIBUTE } ,
14- System :: LibraryLoader :: * ,
14+ System :: {
15+ LibraryLoader :: * ,
16+ Registry :: { RegGetValueW , HKEY_CURRENT_USER , RRF_RT_REG_DWORD } ,
17+ } ,
1518 UI :: { Accessibility :: * , Input :: KeyboardAndMouse :: GetActiveWindow , WindowsAndMessaging :: * } ,
1619 } ,
1720} ;
@@ -199,6 +202,12 @@ fn should_use_dark_mode() -> bool {
199202}
200203
201204fn should_apps_use_dark_mode ( ) -> bool {
205+ if let Some ( apps_use_light_theme) = read_apps_use_light_theme ( ) {
206+ return !apps_use_light_theme;
207+ }
208+ // This undocumented method `ShouldAppsUseDarkMode` may return
209+ // incorrect values on Windows 11.
210+ // See https://github.com/tauri-apps/tao/pull/1165
202211 const UXTHEME_SHOULDAPPSUSEDARKMODE_ORDINAL : u16 = 132 ;
203212 type ShouldAppsUseDarkMode = unsafe extern "system" fn ( ) -> bool ;
204213 static SHOULD_APPS_USE_DARK_MODE : Lazy < Option < ShouldAppsUseDarkMode > > = Lazy :: new ( || unsafe {
@@ -218,6 +227,27 @@ fn should_apps_use_dark_mode() -> bool {
218227 . unwrap_or ( false )
219228}
220229
230+ fn read_apps_use_light_theme ( ) -> Option < bool > {
231+ let mut data: u32 = 0 ;
232+ let mut data_size = std:: mem:: size_of :: < u32 > ( ) as u32 ;
233+ let status = unsafe {
234+ RegGetValueW (
235+ HKEY_CURRENT_USER ,
236+ w ! ( r"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize" ) ,
237+ w ! ( "AppsUseLightTheme" ) ,
238+ RRF_RT_REG_DWORD ,
239+ None ,
240+ Some ( & mut data as * mut _ as _ ) ,
241+ Some ( & mut data_size) ,
242+ )
243+ } ;
244+ if status == ERROR_SUCCESS {
245+ Some ( data != 0 )
246+ } else {
247+ None
248+ }
249+ }
250+
221251fn is_high_contrast ( ) -> bool {
222252 const HCF_HIGHCONTRASTON : u32 = 1 ;
223253
0 commit comments