MCPcopy Create free account
hub / github.com/SpartanJ/eepp / _isOSUsingDarkColorScheme

Function _isOSUsingDarkColorScheme

src/eepp/system/sys.cpp:2024–2263  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2022}
2023
2024static bool _isOSUsingDarkColorScheme() {
2025#if EE_PLATFORM == EE_PLATFORM_WIN
2026 // Checks the registry for the "AppsUseLightTheme" key.
2027 // 0 = Dark, 1 = Light. If key is missing (Win 7/8), default to Light (false).
2028
2029 HKEY hKey;
2030 const wchar_t* subKey = L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
2031 const wchar_t* valueName = L"AppsUseLightTheme";
2032
2033 if ( RegOpenKeyExW( HKEY_CURRENT_USER, subKey, 0, KEY_READ, &hKey ) != ERROR_SUCCESS ) {
2034 return false;
2035 }
2036
2037 DWORD value = 1; // Default to Light
2038 DWORD size = sizeof( DWORD );
2039 LSTATUS status = RegQueryValueExW( hKey, valueName, nullptr, nullptr,
2040 reinterpret_cast<LPBYTE>( &value ), &size );
2041
2042 RegCloseKey( hKey );
2043
2044 if ( status == ERROR_SUCCESS ) {
2045 return ( value == 0 );
2046 }
2047 return false;
2048
2049#elif EE_PLATFORM == EE_PLATFORM_IOS
2050 // Logic: [UIScreen.mainScreen.traitCollection userInterfaceStyle] == 2 (Dark)
2051
2052 // 1. Get UIScreen Class
2053 Class uiScreenClass = objc_getClass( "UIScreen" );
2054 if ( !uiScreenClass )
2055 return false; // Should not happen on iOS
2056
2057 // 2. Call [UIScreen mainScreen]
2058 // We must cast objc_msgSend to the correct function signature
2059 typedef id ( *MainScreenMethod )( Class, SEL );
2060 SEL mainScreenSel = sel_registerName( "mainScreen" );
2061 MainScreenMethod getMainScreen = (MainScreenMethod)objc_msgSend;
2062 id mainScreen = getMainScreen( uiScreenClass, mainScreenSel );
2063 if ( !mainScreen )
2064 return false;
2065
2066 // 3. Call [screen traitCollection]
2067 typedef id ( *TraitCollectionMethod )( id, SEL );
2068 SEL traitCollectionSel = sel_registerName( "traitCollection" );
2069 TraitCollectionMethod getTraitCollection = (TraitCollectionMethod)objc_msgSend;
2070 id traits = getTraitCollection( mainScreen, traitCollectionSel );
2071 if ( !traits )
2072 return false;
2073
2074 // 4. Call [traits userInterfaceStyle]
2075 // Return type is NSInteger (long)
2076 typedef long ( *UserInterfaceStyleMethod )( id, SEL );
2077 SEL styleSel = sel_registerName( "userInterfaceStyle" );
2078 UserInterfaceStyleMethod getStyle = (UserInterfaceStyleMethod)objc_msgSend;
2079 long style = getStyle( traits, styleSel );
2080
2081 // 5. Check constants: UIUserInterfaceStyleLight = 1, UIUserInterfaceStyleDark = 2

Callers 1

Calls 8

getJNIEnvMethod · 0.80
getPlatformHelperMethod · 0.80
c_strMethod · 0.80
find_first_not_ofMethod · 0.80
substrMethod · 0.80
compareMethod · 0.45
lengthMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected