8#import <AppKit/AppKit.h>
20- (NSString*)applicationName;
28 if (
self = [super init]) {
29 _terminationHandler = nil;
35- (void)applicationWillFinishLaunching:(NSNotification*)notification {
37 NSString* applicationName = [
self applicationName];
38 _mainFlutterWindow.title = applicationName;
39 for (NSMenuItem* menuItem in _applicationMenu.itemArray) {
40 menuItem.title = [menuItem.title stringByReplacingOccurrencesOfString:@"APP_NAME"
41 withString:applicationName];
45#pragma mark - Delegate handling
47- (void)addApplicationLifecycleDelegate:(NSObject<FlutterAppLifecycleDelegate>*)delegate {
48 [
self.lifecycleRegistrar addDelegate:delegate];
51- (void)removeApplicationLifecycleDelegate:(NSObject<FlutterAppLifecycleDelegate>*)delegate {
52 [
self.lifecycleRegistrar removeDelegate:delegate];
55#pragma mark Private Methods
57- (NSString*)applicationName {
58 NSString* applicationName =
59 [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
60 if (!applicationName) {
61 applicationName = [NSBundle.mainBundle objectForInfoDictionaryKey:@"CFBundleName"];
63 return applicationName;
66#pragma mark NSApplicationDelegate
68- (void)application:(NSApplication*)application openURLs:(NSArray<NSURL*>*)urls {
69 for (NSObject<FlutterAppLifecycleDelegate>* delegate in
self.lifecycleRegistrar.delegates) {
70 if ([delegate respondsToSelector:@selector(handleOpenURLs:)] &&
71 [delegate handleOpenURLs:urls]) {
77- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication* _Nonnull)sender {
79 if ([
self terminationHandler] == nil || [[
self terminationHandler] shouldTerminate]) {
80 return NSTerminateNow;
86 exitType:kFlutterAppExitTypeCancelable
92 return NSTerminateCancel;
void requestApplicationTermination:exitType:result:(NSApplication *sender,[exitType] FlutterAppExitType type,[result] nullable FlutterResult result)