cocoa: respecting bundle info.plist setting to create the proper applicaiton instance

git-svn-id: trunk@63693 -
This commit is contained in:
dmitry 2020-08-06 04:06:42 +00:00
parent 909fb619f4
commit 62196c0992
2 changed files with 28 additions and 2 deletions

View File

@ -272,6 +272,16 @@ function CocoaPromptUser(const DialogCaption, DialogMessage: String;
EscapeResult: Longint;
sheetOfWindow: NSWindow = nil; modalSheet: Boolean = false): Longint;
// The function tries to initialize the proper application class.
// The desired application class can be specified in info.plit
// by specifying NSPrincipalClass property.
// If then principal class has been found (in the bundle binaries)
// InitApplication function will try to call its "sharedApplication" method.
// If principle class is not specified, then TCocoaApplication is used.
// You should always specify either TCocoaApplication or
// a class derived from TCocoaApplication, in order for LCL to fucntion properly
function InitApplication: TCocoaApplication;
implementation
@ -715,6 +725,22 @@ begin
end;
end;
type
AppClassMethod = objccategory external (NSObject)
function sharedApplication: NSApplication; message 'sharedApplication';
end;
function InitApplication: TCocoaApplication;
var
bun : NSBundle;
begin
bun := NSBundle.mainBundle;
if Assigned(bun) and Assigned(bun.principalClass) then
Result := TCocoaApplication(NSObject(bun.principalClass).sharedApplication)
else
Result := TCocoaApplication(TCocoaApplication.sharedApplication);
end;
// the implementation of the utility methods
{$I cocoaobject.inc}
// the implementation of the winapi compatibility methods

View File

@ -38,7 +38,7 @@ begin
ScreenInfo.PixelsPerInchY := CocoaBasePPI;
{ Creates the application NSApp object }
FNSApp := TCocoaApplication(TCocoaApplication.sharedApplication);
FNSApp := InitApplication;
FNSApp_Delegate := TAppDelegate.alloc.init;
FNSApp.setDelegate(FNSApp_Delegate);
{$ifdef COCOALOOPOVERRIDE}
@ -52,7 +52,7 @@ end;
procedure TCocoaWidgetSet.SendCheckSynchronizeMessage;
begin
TCocoaApplication.sharedApplication
InitApplication
.performSelectorOnMainThread_withObject_waitUntilDone(
ObjCSelector('lclSyncCheck:'), nil, false);
end;