8 #import <AppKit/AppKit.h>
10 #include "flutter/fml/logging.h"
13 #include "flutter/shell/platform/embedder/embedder.h"
20 - (NSString*)applicationName;
27 - (instancetype)init {
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
48 [
self.lifecycleRegistrar addDelegate: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:)] &&
77 - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication* _Nonnull)sender {
79 if ([
self terminationHandler] == nil || [[
self terminationHandler] shouldTerminate]) {
80 return NSTerminateNow;
86 exitType:kFlutterAppExitTypeCancelable
92 return NSTerminateCancel;