Flutter Engine
The Flutter Engine
Instance Methods | Properties | List of all members
FlutterEngineTerminationHandler Class Reference

#import <FlutterEngine_Internal.h>

Inheritance diagram for FlutterEngineTerminationHandler:

Instance Methods

(instancetype) - initWithEngine:terminator:
 
(void) - handleRequestAppExitMethodCall:result:
 
(void) - requestApplicationTermination:exitType:result:
 
(instancetype) - initWithEngine:terminator: [implementation]
 
(void) - requestApplicationTermination:exitType:result: [implementation]
 

Properties

BOOL shouldTerminate
 
BOOL acceptingRequests
 

Detailed Description

A handler interface for handling application termination that the FlutterAppDelegate can use to coordinate an application exit by sending messages through the platform channel managed by the engine.

Definition at line 188 of file FlutterEngine.mm.

Method Documentation

◆ handleRequestAppExitMethodCall:result:

- (void) handleRequestAppExitMethodCall: (NSDictionary<NSString*, id>*)  data
result: (FlutterResult result 

Definition at line 190 of file FlutterEngine.mm.

213 :(NSDictionary<NSString*, id>*)arguments
215 NSString* type = arguments[@"type"];
216 // Ignore the "exitCode" value in the arguments because AppKit doesn't have
217 // any good way to set the process exit code other than calling exit(), and
218 // that bypasses all of the native applicationShouldExit shutdown events,
219 // etc., which we don't want to skip.
220
221 FlutterAppExitType exitType =
222 [type isEqualTo:@"cancelable"] ? kFlutterAppExitTypeCancelable : kFlutterAppExitTypeRequired;
223
224 [self requestApplicationTermination:[NSApplication sharedApplication]
225 exitType:exitType
226 result:result];
227}
void(^ FlutterResult)(id _Nullable result)
GLenum type
GAsyncResult * result

◆ initWithEngine:terminator: [1/2]

- (instancetype) initWithEngine: (FlutterEngine*)  engine
terminator: (FlutterTerminationCallback terminator 
implementation

Definition at line 190 of file FlutterEngine.mm.

194 terminator:(FlutterTerminationCallback)terminator {
195 self = [super init];
196 _acceptingRequests = NO;
197 _engine = engine;
198 _terminator = terminator ? terminator : ^(id sender) {
199 // Default to actually terminating the application. The terminator exists to
200 // allow tests to override it so that an actual exit doesn't occur.
201 [[NSApplication sharedApplication] terminate:sender];
202 };
203 id<NSApplicationDelegate> appDelegate = [[NSApplication sharedApplication] delegate];
204 if ([appDelegate respondsToSelector:@selector(setTerminationHandler:)]) {
205 FlutterAppDelegate* flutterAppDelegate = reinterpret_cast<FlutterAppDelegate*>(appDelegate);
206 flutterAppDelegate.terminationHandler = self;
207 }
208 return self;
209}
FlutterEngine engine
Definition: main.cc:68
FlutterEngineTerminationHandler * terminationHandler
fml::scoped_nsobject< FlutterEngine > _engine
FlutterTerminationCallback _terminator
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterTerminationCallback)(id _Nullable sender)

◆ initWithEngine:terminator: [2/2]

- (instancetype) initWithEngine: (FlutterEngine *)  engine
terminator: (nullable FlutterTerminationCallback terminator 

◆ requestApplicationTermination:exitType:result: [1/2]

- (void) requestApplicationTermination: (id sender
exitType: (FlutterAppExitType)  type
result: (nullable FlutterResult result 
implementation

Definition at line 190 of file FlutterEngine.mm.

231 :(id)sender
232 exitType:(FlutterAppExitType)type
233 result:(nullable FlutterResult)result {
234 _shouldTerminate = YES;
235 if (![self acceptingRequests]) {
236 // Until the Dart application has signaled that it is ready to handle
237 // termination requests, the app will just terminate when asked.
238 type = kFlutterAppExitTypeRequired;
239 }
240 switch (type) {
241 case kFlutterAppExitTypeCancelable: {
243 FlutterMethodCall* methodCall =
244 [FlutterMethodCall methodCallWithMethodName:@"System.requestAppExit" arguments:nil];
245 [_engine sendOnChannel:kFlutterPlatformChannel
246 message:[codec encodeMethodCall:methodCall]
247 binaryReply:^(NSData* _Nullable reply) {
248 NSAssert(_terminator, @"terminator shouldn't be nil");
249 id decoded_reply = [codec decodeEnvelope:reply];
250 if ([decoded_reply isKindOfClass:[FlutterError class]]) {
251 FlutterError* error = (FlutterError*)decoded_reply;
252 NSLog(@"Method call returned error[%@]: %@ %@", [error code], [error message],
253 [error details]);
254 _terminator(sender);
255 return;
256 }
257 if (![decoded_reply isKindOfClass:[NSDictionary class]]) {
258 NSLog(@"Call to System.requestAppExit returned an unexpected object: %@",
259 decoded_reply);
260 _terminator(sender);
261 return;
262 }
263 NSDictionary* replyArgs = (NSDictionary*)decoded_reply;
264 if ([replyArgs[@"response"] isEqual:@"exit"]) {
265 _terminator(sender);
266 } else if ([replyArgs[@"response"] isEqual:@"cancel"]) {
267 _shouldTerminate = NO;
268 }
269 if (result != nil) {
270 result(replyArgs);
271 }
272 }];
273 break;
274 }
275 case kFlutterAppExitTypeRequired:
276 NSAssert(_terminator, @"terminator shouldn't be nil");
277 _terminator(sender);
278 break;
279 }
280}
NSData * encodeMethodCall:(FlutterMethodCall *call)
id decodeEnvelope:(NSData *envelope)
instancetype sharedInstance()
instancetype methodCallWithMethodName:arguments:(NSString *method,[arguments] id _Nullable arguments)
const uintptr_t id

◆ requestApplicationTermination:exitType:result: [2/2]

- (void) requestApplicationTermination: (NSApplication *)  sender
exitType: (FlutterAppExitType)  type
result: (nullable FlutterResult result 

Property Documentation

◆ acceptingRequests

- (BOOL) acceptingRequests
readwritenonatomicassign

Definition at line 60 of file FlutterEngine_Internal.h.

◆ shouldTerminate

- (BOOL) shouldTerminate
readnonatomicassign

Definition at line 59 of file FlutterEngine_Internal.h.


The documentation for this class was generated from the following files: