You've already forked CEF4Delphi
mirror of
https://github.com/salvadordf/CEF4Delphi.git
synced 2025-06-22 22:17:48 +02:00
Check macOS version before initialization
This commit is contained in:
@ -384,6 +384,10 @@ type
|
|||||||
function CheckCEFDLL : boolean; virtual;
|
function CheckCEFDLL : boolean; virtual;
|
||||||
function CheckWindowsVersion: boolean; virtual;
|
function CheckWindowsVersion: boolean; virtual;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF MACOSX}
|
||||||
|
function CheckMacOSVersion : boolean; virtual;
|
||||||
|
{$ENDIF}
|
||||||
|
function CheckOSVersion: boolean; virtual;
|
||||||
procedure ShowErrorMessageDlg(const aError : string); virtual;
|
procedure ShowErrorMessageDlg(const aError : string); virtual;
|
||||||
function ParseProcessType : TCefProcessType;
|
function ParseProcessType : TCefProcessType;
|
||||||
procedure AddCustomCommandLineSwitches(var aKeys, aValues : TStringList); virtual;
|
procedure AddCustomCommandLineSwitches(var aKeys, aValues : TStringList); virtual;
|
||||||
@ -1802,7 +1806,7 @@ uses
|
|||||||
System.Math, System.IOUtils, System.SysUtils,
|
System.Math, System.IOUtils, System.SysUtils,
|
||||||
{$IFDEF MSWINDOWS}WinApi.TlHelp32, WinApi.PSAPI,{$ENDIF}
|
{$IFDEF MSWINDOWS}WinApi.TlHelp32, WinApi.PSAPI,{$ENDIF}
|
||||||
{$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF}
|
{$IFDEF LINUX}{$IFDEF FMX}Posix.Unistd, Posix.Stdio,{$ENDIF}{$ENDIF}
|
||||||
{$IFDEF MACOS}Posix.Stdio, uCEFMacOSFunctions,{$ENDIF}
|
{$IFDEF MACOS}Posix.Stdio,{$ENDIF}
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
|
Math, {$IFDEF DELPHI14_UP}IOUtils,{$ENDIF} SysUtils,
|
||||||
{$IFDEF FPC}
|
{$IFDEF FPC}
|
||||||
@ -1812,6 +1816,7 @@ uses
|
|||||||
TlHelp32, {$IFDEF MSWINDOWS}PSAPI,{$ENDIF}
|
TlHelp32, {$IFDEF MSWINDOWS}PSAPI,{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
{$IFDEF MACOSX}uCEFMacOSFunctions,{$ENDIF}
|
||||||
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
uCEFLibFunctions, uCEFMiscFunctions, uCEFCommandLine, uCEFConstants,
|
||||||
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFCompletionCallback,
|
uCEFSchemeHandlerFactory, uCEFCookieManager, uCEFApp, uCEFCompletionCallback,
|
||||||
uCEFWaitableEvent;
|
uCEFWaitableEvent;
|
||||||
@ -2590,11 +2595,44 @@ begin
|
|||||||
end;
|
end;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFDEF MACOSX}
|
||||||
|
function TCefApplicationCore.CheckMacOSVersion : boolean;
|
||||||
|
begin
|
||||||
|
// Chromium crashes with the compatibility mode and old OS versions
|
||||||
|
// https://source.chromium.org/chromium/chromium/src/+/main:base/mac/mac_util.mm;drc=6166dba74ab72a84a6c7c575cacb438e6bfb2c66;l=338
|
||||||
|
// https://support.google.com/chrome/a/answer/7100626?hl=en
|
||||||
|
if CheckRealMacOSVersion(11, 0) then
|
||||||
|
Result := True
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
FStatus := asErrorWindowsVersion;
|
||||||
|
FLastErrorMessage := 'Unsupported macOS version !' +
|
||||||
|
CRLF + CRLF +
|
||||||
|
'Chromium requires macOS 11.0 or later.';
|
||||||
|
ShowErrorMessageDlg(FLastErrorMessage);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
function TCefApplicationCore.CheckOSVersion: boolean;
|
||||||
|
begin
|
||||||
|
{$IFDEF MSWINDOWS}
|
||||||
|
Result := CheckWindowsVersion;
|
||||||
|
{$ELSE}
|
||||||
|
{$IFDEF MACOSX}
|
||||||
|
Result := CheckMacOSVersion;
|
||||||
|
{$ELSE}
|
||||||
|
Result := True; // Linux
|
||||||
|
{$ENDIF}
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
function TCefApplicationCore.CheckCEFLibrary : boolean;
|
function TCefApplicationCore.CheckCEFLibrary : boolean;
|
||||||
var
|
var
|
||||||
TempOldDir : string;
|
TempOldDir : string;
|
||||||
begin
|
begin
|
||||||
if not(FCheckCEFFiles) or (FProcessType <> ptBrowser) then
|
if (FProcessType <> ptBrowser) then
|
||||||
begin
|
begin
|
||||||
Result := True;
|
Result := True;
|
||||||
exit;
|
exit;
|
||||||
@ -2606,9 +2644,9 @@ begin
|
|||||||
chdir(GetModulePath);
|
chdir(GetModulePath);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Result := CheckCEFResources;
|
Result := (not(FCheckCEFFiles) or CheckCEFResources) and CheckOSVersion;
|
||||||
{$IFDEF MSWINDOWS}
|
{$IFDEF MSWINDOWS}
|
||||||
Result := Result and CheckWindowsVersion and CheckCEFDLL;
|
Result := Result and (not(FCheckCEFFiles) or CheckCEFDLL);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
if FSetCurrentDir then chdir(TempOldDir);
|
if FSetCurrentDir then chdir(TempOldDir);
|
||||||
|
@ -12,16 +12,20 @@ unit uCEFMacOSFunctions;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
System.UITypes,
|
|
||||||
{$IFDEF MACOS}
|
{$IFDEF MACOS}
|
||||||
FMX.Helpers.Mac, System.Messaging, Macapi.CoreFoundation, Macapi.Foundation,
|
System.UITypes, FMX.Helpers.Mac, System.Messaging, Macapi.CoreFoundation, Macapi.Foundation,
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
SysCtl, SysUtils, Unix,
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
uCEFMacOSConstants;
|
uCEFMacOSConstants;
|
||||||
|
|
||||||
{$IFDEF MACOSX}
|
{$IFDEF MACOSX}
|
||||||
function KeyToMacOSKeyCode(aKey : Word): integer;
|
function GetSysCtlValueByName(const aName: AnsiString) : string;
|
||||||
|
function CheckRealMacOSVersion(aMajor, aMinor: integer): boolean;
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
{$IFDEF MACOS}
|
{$IFDEF MACOS}
|
||||||
|
function KeyToMacOSKeyCode(aKey : Word): integer;
|
||||||
procedure CopyCEFFramework;
|
procedure CopyCEFFramework;
|
||||||
procedure CopyCEFHelpers(const aProjectName : string);
|
procedure CopyCEFHelpers(const aProjectName : string);
|
||||||
procedure ShowMessageCF(const aHeading, aMessage : string; const aTimeoutInSecs : double = 0);
|
procedure ShowMessageCF(const aHeading, aMessage : string; const aTimeoutInSecs : double = 0);
|
||||||
@ -33,7 +37,7 @@ implementation
|
|||||||
{$IFDEF MACOS}
|
{$IFDEF MACOS}
|
||||||
uses
|
uses
|
||||||
System.SysUtils, System.Types, System.IOUtils, Posix.Stdio, FMX.Types,
|
System.SysUtils, System.Types, System.IOUtils, Posix.Stdio, FMX.Types,
|
||||||
uCEFMiscFunctions;
|
Posix.SysSysctl, uCEFMiscFunctions;
|
||||||
|
|
||||||
const
|
const
|
||||||
PRJ_HELPER_SUBFIX = '_helper';
|
PRJ_HELPER_SUBFIX = '_helper';
|
||||||
@ -49,6 +53,93 @@ const
|
|||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
|
|
||||||
{$IFDEF MACOSX}
|
{$IFDEF MACOSX}
|
||||||
|
function GetSysCtlValueByName(const aName: AnsiString) : string;
|
||||||
|
{$IFDEF MACOS}
|
||||||
|
var
|
||||||
|
Buffer: TArray<Byte>;
|
||||||
|
BufferLength: LongWord;
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
var
|
||||||
|
Buffer : PChar;
|
||||||
|
BufferLength : size_t;
|
||||||
|
{$ENDIF}
|
||||||
|
begin
|
||||||
|
{$IFDEF MACOS}
|
||||||
|
if (SysCtlByName(MarshaledAString(aName), nil, @BufferLength, nil, 0) = 0) and (BufferLength > 0) then
|
||||||
|
begin
|
||||||
|
SetLength(Buffer, BufferLength);
|
||||||
|
try
|
||||||
|
if (SysCtlByName(MarshaledAString(aName), @Buffer[0], @BufferLength, nil, 0) = 0) then
|
||||||
|
Result := string(MarshaledAString(@Buffer[0]));
|
||||||
|
finally
|
||||||
|
SetLength(Buffer, 0);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
{$IFDEF DARWIN}
|
||||||
|
if (fpSysCtlByName(PChar(aName), nil, @BufferLength, nil, 0) = 0) and (BufferLength > 0) then
|
||||||
|
begin
|
||||||
|
GetMem(Buffer, BufferLength);
|
||||||
|
try
|
||||||
|
if (fpSysCtlByName(PChar(aName), Buffer, @BufferLength, nil, 0) = 0) then
|
||||||
|
Result := Buffer;
|
||||||
|
finally
|
||||||
|
FreeMem(Buffer);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
end;
|
||||||
|
|
||||||
|
function CheckRealMacOSVersion(aMajor, aMinor: integer): boolean;
|
||||||
|
var
|
||||||
|
TempValue : string;
|
||||||
|
TempMajor, TempMinor, i : integer;
|
||||||
|
begin
|
||||||
|
TempMajor := 0;
|
||||||
|
TempMinor := 0;
|
||||||
|
TempValue := trim(GetSysCtlValueByName('kern.osproductversion'));
|
||||||
|
|
||||||
|
if (length(TempValue) > 0) then
|
||||||
|
begin
|
||||||
|
i := pos('.', TempValue);
|
||||||
|
if (i > 0) then
|
||||||
|
begin
|
||||||
|
TempMajor := StrToIntDef(copy(TempValue, 1, pred(i)), 0);
|
||||||
|
TempValue := copy(TempValue, succ(i), length(TempValue));
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
i := pos(' ', TempValue);
|
||||||
|
if (i > 0) then
|
||||||
|
begin
|
||||||
|
TempMajor := StrToIntDef(copy(TempValue, 1, pred(i)), 0);
|
||||||
|
TempValue := copy(TempValue, succ(i), length(TempValue));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if (length(TempValue) > 0) then
|
||||||
|
begin
|
||||||
|
i := pos('.', TempValue);
|
||||||
|
if (i > 0) then
|
||||||
|
TempMinor := StrToIntDef(copy(TempValue, 1, pred(i)), 0)
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
i := pos(' ', TempValue);
|
||||||
|
if (i > 0) then
|
||||||
|
TempMinor := StrToIntDef(copy(TempValue, 1, pred(i)), 0)
|
||||||
|
else
|
||||||
|
TempMinor := StrToIntDef(TempValue, 0);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Result := (TempMajor > aMajor) or
|
||||||
|
((TempMajor = aMajor) and (TempMinor >= aMinor));
|
||||||
|
end;
|
||||||
|
{$ENDIF}
|
||||||
|
|
||||||
|
{$IFDEF MACOS}
|
||||||
// Key Code translation following the information found in these documents :
|
// Key Code translation following the information found in these documents :
|
||||||
// https://developer.apple.com/library/archive/documentation/mac/pdf/MacintoshToolboxEssentials.pdf
|
// https://developer.apple.com/library/archive/documentation/mac/pdf/MacintoshToolboxEssentials.pdf
|
||||||
// https://eastmanreference.com/complete-list-of-applescript-key-codes
|
// https://eastmanreference.com/complete-list-of-applescript-key-codes
|
||||||
@ -178,9 +269,7 @@ begin
|
|||||||
else Result := 0;
|
else Result := 0;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$ENDIF}
|
|
||||||
|
|
||||||
{$IFDEF MACOS}
|
|
||||||
procedure CopyAllFiles(const aSrcPath, aDstPath: string);
|
procedure CopyAllFiles(const aSrcPath, aDstPath: string);
|
||||||
var
|
var
|
||||||
TempDirectories, TempFiles : TStringDynArray;
|
TempDirectories, TempFiles : TStringDynArray;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
"UpdateLazPackages" : [
|
"UpdateLazPackages" : [
|
||||||
{
|
{
|
||||||
"ForceNotify" : true,
|
"ForceNotify" : true,
|
||||||
"InternalVersion" : 651,
|
"InternalVersion" : 652,
|
||||||
"Name" : "cef4delphi_lazarus.lpk",
|
"Name" : "cef4delphi_lazarus.lpk",
|
||||||
"Version" : "128.4.9"
|
"Version" : "128.4.9"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user