Skip to content

Commit

Permalink
theme manager: add mac and windows theme detection
Browse files Browse the repository at this point in the history
  • Loading branch information
vgmoose committed Nov 29, 2023
1 parent baf2b98 commit dbe6a93
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 5 additions & 5 deletions gui/AppCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ AppCard::AppCard(Package& package, AppList* list)

return new ImageElement(RAMFS "res/default.png");
}, !list)
, version(("v" + package->getVersion()).c_str(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, status(package->statusString(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, appname(package->getTitle().c_str(), TEXT_SIZE + 3, &HBAS::ThemeManager::textPrimary)
, author(package->getAuthor().c_str(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, statusicon((RAMFS "res/" + std::string(package->statusString()) + ".png").c_str())
, version(("v" + package.getVersion()).c_str(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, status(package.statusString(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, appname(package.getTitle().c_str(), TEXT_SIZE + 3, &HBAS::ThemeManager::textPrimary)
, author(package.getAuthor().c_str(), TEXT_SIZE, &HBAS::ThemeManager::textSecondary)
, statusicon((RAMFS "res/" + std::string(package.statusString()) + ".png").c_str())
{
// fixed width+height of one app card
this->width = 256; // + 9px margins
Expand Down
26 changes: 24 additions & 2 deletions gui/ThemeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,35 @@ namespace HBAS::ThemeManager
void themeManagerInit()
{
// Detect if Switch is using dark theme
#ifdef SWITCH
#ifdef SWITCH
setsysInitialize();
static ColorSetId sysTheme = ColorSetId_Light;
setsysGetColorSetId(&sysTheme);
isDarkMode = (sysTheme == ColorSetId_Dark);
setsysExit();
#endif
#endif

#ifdef __APPLE__
if (system("defaults read -g AppleInterfaceStyle 2>/dev/null") == 0) {
isDarkMode = true;
}
#endif

#ifdef _WIN32
HKEY hKey;
DWORD dwRegValue, dwRegType, dwRegSize = sizeof(DWORD);
if (RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, TEXT("AppsUseLightTheme"), NULL, &dwRegType, (LPBYTE)&dwRegValue, &dwRegSize) == ERROR_SUCCESS)
{
isDarkMode = !dwRegValue;
}
RegCloseKey(hKey);
}
#endif

// TODO: check some preference to override the system theme

// Set colors for dark mode
if (isDarkMode)
{
Expand Down

0 comments on commit dbe6a93

Please sign in to comment.