Skip to content

Instantly share code, notes, and snippets.

@an01f01
Created January 13, 2025 20:20
Show Gist options
  • Save an01f01/39d125cc626c4030075fa7e88d463666 to your computer and use it in GitHub Desktop.
Save an01f01/39d125cc626c4030075fa7e88d463666 to your computer and use it in GitHub Desktop.
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