5#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterAppLifecycleDelegate.h"
6#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterAppLifecycleDelegate_Internal.h"
8#include <AppKit/AppKit.h>
9#include <AppKit/NSApplication.h>
10#include <Foundation/Foundation.h>
11#include <objc/message.h>
13#include "flutter/fml/logging.h"
14#include "flutter/fml/paths.h"
18- (void)addObserverFor:(NSString*)name selector:(
SEL)selector {
19 [[NSNotificationCenter defaultCenter] addObserver:self selector:selector name:name object:nil];
26#ifdef OBSERVE_NOTIFICATION
27#error OBSERVE_NOTIFICATION ALREADY DEFINED!
29#define OBSERVE_NOTIFICATION(SELECTOR) \
30 [self addObserverFor:NSApplication##SELECTOR##Notification selector:@selector(handle##SELECTOR:)]
47#undef OBSERVE_NOTIFICATION
49 _delegates = [NSPointerArray weakObjectsPointerArray];
55 return x != 0 && (
x & (
x - 1)) == 0;
59 [_delegates addPointer:(__bridge void*)delegate];
66 NSUInteger index = [[_delegates allObjects] indexOfObject:delegate];
67 if (index != NSNotFound) {
68 [_delegates removePointerAtIndex:index];
75#ifdef DISTRIBUTE_NOTIFICATION
76#error DISTRIBUTE_NOTIFICATION ALREADY DEFINED!
78#define DISTRIBUTE_NOTIFICATION(SELECTOR) \
79 -(void)handle##SELECTOR : (NSNotification*)notification { \
80 for (NSObject<FlutterAppLifecycleDelegate> * delegate in _delegates) { \
81 if ([delegate respondsToSelector:@selector(handle##SELECTOR:)]) { \
82 [delegate handle##SELECTOR:notification]; \
102#undef DISTRIBUTE_NOTIFICATION
#define DISTRIBUTE_NOTIFICATION(SELECTOR)
#define OBSERVE_NOTIFICATION(SELECTOR)
NSPointerArray * _delegates
static BOOL IsPowerOfTwo(NSUInteger x)