unit App.Starter;
interface
{$INCLUDE 'Conditional.inc'}
uses
System.SysUtils,
FMX.
Platform;
type
TAppStarter =
class
private
FPresenterFactory: TFunc<IInterface>;
FMainPresenter: IInterface;
FApplicationEventService: IFMXApplicationEventService;
procedure GetPlatformServices;
function ApplicationEventHandler( AAppEvent: TApplicationEvent; AContext: TObject ): Boolean;
{$IFDEF MOBILE}
private // bei Mobile-Platform verstecken
{$ELSE}
public // sonst öffentlich aufrufbar
{$ENDIF}
procedure CreateMainPresenter;
public
constructor Create( PresenterFactory: TFunc<IInterface> );
end;
implementation
{ TAppStarter }
function TAppStarter.ApplicationEventHandler( AAppEvent: TApplicationEvent; AContext: TObject ): Boolean;
begin
if AAppEvent = TApplicationEvent.FinishedLaunching
then
CreateMainPresenter;
Result := True;
end;
constructor TAppStarter.Create( PresenterFactory: TFunc<IInterface> );
begin
inherited Create;
FPresenterFactory := PresenterFactory;
GetPlatformServices;
end;
procedure TAppStarter.CreateMainPresenter;
begin
if not Assigned( FMainPresenter )
then
FMainPresenter := FPresenterFactory( );
end;
procedure TAppStarter.GetPlatformServices;
begin
if TPlatformServices.Current.SupportsPlatformService( IFMXApplicationEventService, FApplicationEventService )
then
FApplicationEventService.SetApplicationEventHandler( Self.ApplicationEventHandler );
end;
end.