@@ -8,9 +8,10 @@ interface
88 Classes, SysUtils, Generics.Collections, Controls, RegExpr, Math, FileUtil,
99 StrUtils, Graphics, GraphUtil, LCLIntf, Forms, Clipbrd, Process, ActnList, Menus, Dialogs,
1010 Character, DateUtils, laz.VirtualTrees, SynEdit, SynCompletion, fphttpclient,
11- { $IFDEF WINDOWS} Windows, Registry, { $ENDIF} DelphiCompat,
11+ { $IFDEF WINDOWS} Windows, Registry, uDarkStyleParams, { $ENDIF} DelphiCompat,
1212 dbconnection, dbstructures, jsonregistry, lazaruscompat, fpjson, SynEditKeyCmds, LazFileUtils, gettext, LazUTF8,
13- IniFiles, GraphType, Sockets, uDarkStyleParams, Contnrs;
13+ IniFiles, GraphType, Sockets, Contnrs
14+ { $IFDEF DARWIN} , MacOSAll { $ENDIF} ;
1415
1516type
1617
@@ -416,6 +417,7 @@ TAppSettings = class(TObject)
416417 procedure Help (Sender: TObject; Anchor: String);
417418 function IsPortFree (APort: Word; const AIP: string = ' 127.0.0.1' ): Boolean;
418419 function GetThemeColor (Color: TColor): TColor;
420+ function ThemeIsDark : Boolean;
419421 function ProcessExists (pid: Cardinal; ExeNamePattern: String): Boolean;
420422 function SynCompletionProposalPrettyText (ImageIndex: Integer; LeftText, CenterText, RightText: String; LeftColor: TColor=-1 ; CenterColor: TColor=-1 ; RightColor: TColor=-1 ): String;
421423 function PopupComponent (Sender: TObject): TComponent;
@@ -2361,7 +2363,7 @@ function MessageDialog(const Title, Msg: string; DlgType: TMsgDlgType; Buttons:
23612363 Dialog.Caption := MainForm.ActiveConnection.Parameters.SessionName + ' : ' + Dialog.Caption;
23622364 rx := TRegExpr.Create;
23632365 rx.Expression := ' https?://[^\s"]+' ;
2364- if IsDarkModeEnabled then
2366+ if ThemeIsDark then
23652367 Dialog.Text := Msg
23662368 else // See issue #2036
23672369 Dialog.Text := rx.Replace(Msg, ' <a href="$0">$0</a>' , True);
@@ -2830,6 +2832,40 @@ function GetThemeColor(Color: TColor): TColor;
28302832end ;
28312833
28322834
2835+ function ThemeIsDark : Boolean;
2836+ { $IFDEF DARWIN}
2837+ var
2838+ cfValue: CFPropertyListRef;
2839+ s: CFStringRef;
2840+ buf: array [0 ..15 ] of UniChar;
2841+ { $ENDIF}
2842+ begin
2843+ { $IFDEF WINDOWS}
2844+ // This is not a system detection, but a more precise switch in MetaDarkStyle.
2845+ // On Windows, the user may have forced MetaDarkStyle's light mode when the system is in dark mode.
2846+ Result := uDarkStyleParams.IsDarkModeEnabled;
2847+ { $ENDIF}
2848+ { $IFDEF LINUX}
2849+ // Not yet possible to detect the system's dark mode. Ideas welcome.
2850+ Result := False;
2851+ { $ENDIF}
2852+ { $IFDEF DARWIN}
2853+ // Detect system's dark mode on macOS
2854+ cfValue := CFPreferencesCopyAppValue(
2855+ CFSTR(' AppleInterfaceStyle' ),
2856+ CFSTR(' .GlobalPreferences' )
2857+ );
2858+ if (cfValue <> nil ) and (CFGetTypeID(cfValue) = CFStringGetTypeID) then begin
2859+ s := CFStringRef(cfValue);
2860+ if CFStringGetLength(s) <= Length(buf) then begin
2861+ CFStringGetCharacters(s, CFRangeMake(0 , CFStringGetLength(s)), @buf[0 ]);
2862+ Result := CFStringCompare(s, CFSTR(' Dark' ), 0 ) = kCFCompareEqualTo;
2863+ end ;
2864+ CFRelease(cfValue);
2865+ end ;
2866+ { $ENDIF}
2867+ end ;
2868+
28332869function ProcessExists (pid: Cardinal; ExeNamePattern: String): Boolean;
28342870{ var
28352871 Proc: TProcessEntry32;
0 commit comments