Created
January 13, 2025 20:20
-
-
Save an01f01/39d125cc626c4030075fa7e88d463666 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit PlatformColorMode; | |
interface | |
uses | |
FMX.Platform | |
{$IFDEF MSWINDOWS} | |
, System.SysUtils, System.Win.Registry, Winapi.Windows | |
{$ENDIF} | |
; | |
function GetSystemTheme: TSystemThemeKind; | |
implementation | |
function GetSystemTheme: TSystemThemeKind; | |
{$IFDEF MSWINDOWS} | |
const | |
RegThemeKey = 'Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\'; | |
RegThemeVal = 'AppsUseLightTheme'; | |
{$ENDIF} | |
var | |
{$IFDEF MSWINDOWS} | |
Reg: TRegistry; | |
{$ELSE} | |
LService: IFMXSystemAppearanceService; | |
{$ENDIF} | |
begin | |
Result := TSystemThemeKind.Unspecified; | |
{$IFDEF MSWINDOWS} | |
Reg := TRegistry.Create; | |
try | |
Reg.RootKey := HKEY_CURRENT_USER; | |
if Reg.KeyExists(RegThemeKey) then | |
if Reg.OpenKey(RegThemeKey, False) then | |
try | |
if Reg.ValueExists(RegThemeVal) then | |
if Reg.ReadInteger(RegThemeVal) = 0 then | |
Result := TSystemThemeKind.Dark | |
else | |
Result := TSystemThemeKind.Light; | |
finally | |
Reg.CloseKey; | |
end; | |
finally | |
Reg.Free; | |
end; | |
{$ELSE} | |
if TPlatformServices.Current.SupportsPlatformService(IFMXSystemAppearanceService, LService) then | |
Result := LService.GetSystemThemeKind; | |
{$ENDIF} | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment