fix: Theme detection issues on all OSes

This commit is contained in:
WerWolv
2022-06-30 15:09:57 +02:00
parent 19f99bab0c
commit bb429aae62
5 changed files with 20 additions and 3 deletions

View File

@@ -5,5 +5,6 @@
#include <string>
extern "C" void openWebpageMacos(const char *url);
extern "C" bool isMacosSystemDarkModeEnabled();
#endif

View File

@@ -13,4 +13,15 @@
CFRelease(urlRef);
}
bool isMacosSystemDarkModeEnabled() {
NSString * appleInterfaceStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"];
if (appleInterfaceStyle && [appleInterfaceStyle length] > 0) {
return [[appleInterfaceStyle lowercaseString] containsString:@"dark"];
} else {
return false;
}
}
}
#endif

View File

@@ -38,7 +38,7 @@ namespace hex {
auto exitCode = WEXITSTATUS(pclose(pipe));
if (exitCode != 0) return;
EventManager::post<RequestChangeTheme>(hex::containsIgnoreCase(result, "dark") ? 1 : 2);
EventManager::post<RequestChangeTheme>(hex::containsIgnoreCase(result, "light") ? 2 : 1);
});
if (themeFollowSystem)

View File

@@ -5,6 +5,7 @@
#include <hex/api/content_registry.hpp>
#include <hex/api/event.hpp>
#include <hex/helpers/utils_macos.hpp>
#include <hex/helpers/logger.hpp>
#include <nlohmann/json.hpp>
@@ -23,8 +24,10 @@ namespace hex {
EventManager::subscribe<EventOSThemeChanged>(this, [themeFollowSystem] {
if (!themeFollowSystem) return;
// TODO: Implement this when MacOS build is working again
EventManager::post<RequestChangeTheme>(1);
if (!isMacosSystemDarkModeEnabled())
EventManager::post<RequestChangeTheme>(2);
else
EventManager::post<RequestChangeTheme>(1);
});
if (themeFollowSystem)

View File

@@ -34,6 +34,8 @@ static void detectSystemTheme() {
auto error = RegQueryValueEx(hkey, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast<LPBYTE>(&value), &size);
if (error == ERROR_SUCCESS) {
EventManager::post<RequestChangeTheme>(value == 0 ? 1 : 2);
} else {
EventManager::post<RequestChangeTheme>(1);
}
}
});