Skip to content

Commit

Permalink
Merge pull request #1399 from DominiqueFuchs/master
Browse files Browse the repository at this point in the history
Integrated registry check on windows when hasDarkSystray is called.
  • Loading branch information
Camila Ayres authored Sep 6, 2019
2 parents c3b270b + 0841fe8 commit c4dfe57
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/common/utility_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,36 @@ void setLaunchOnStartup_private(const QString &appName, const QString &guiName,
}
}

// TODO: Right now only detection on toggle/startup, not when windows theme is switched while nextcloud is running
static inline bool hasDarkSystray_private()
{
return true;
bool hasDarkSystray = true;
// Open registry key first, continue only on success (may be legitimately absent in earlier windows versions)
HKEY hKey;
LONG lRes = RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey);

// classical windows function - preserve buff size for DWORD, call ExW version, store regkey value in nResult
if (lRes == ERROR_SUCCESS) {
DWORD dwBufferSize(sizeof(DWORD));
DWORD nResult(0);

// https://docs.microsoft.com/en-us/windows/win32/api/winreg/nf-winreg-regqueryvalueexw
LONG nError = ::RegQueryValueExW(hKey,
L"SystemUsesLightTheme",
NULL,
NULL,
reinterpret_cast<LPBYTE>(&nResult),
&dwBufferSize);

// if RegQuery returned no error and light theme was found, change systray return value
if (nError == ERROR_SUCCESS && nResult == 1)
hasDarkSystray = false;

return hasDarkSystray;
} else {
// fallback to true if regkey could not be determined
return hasDarkSystray;
}
}

QVariant Utility::registryGetKeyValue(HKEY hRootKey, const QString &subKey, const QString &valueName)
Expand Down

0 comments on commit c4dfe57

Please sign in to comment.