Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 64c30df

Browse files
committed
Remove debugging prints
1 parent c13ae95 commit 64c30df

File tree

7 files changed

+104
-107
lines changed

7 files changed

+104
-107
lines changed

shell/platform/darwin/macos/framework/Headers/FlutterAppLifecycleDelegate.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,13 @@ NS_ASSUME_NONNULL_BEGIN
2424
@optional
2525
/**
2626
* Called when the |FlutterAppDelegate| gets the applicationWillFinishLaunching
27-
* notification. This only notifies that the notification occurred, it doesn't
28-
* allow a response. Only the application can respond to the notification by
29-
* overriding that handler in the |FlutterAppDelegate| subclass of the
30-
* application.
27+
* notification.
3128
*/
3229
- (void)handleWillFinishLaunching:(NSNotification*)notification;
3330

3431
/**
3532
* Called when the |FlutterAppDelegate| gets the applicationDidFinishLaunching
36-
* notification. This only notifies that the notification occurred, it doesn't
37-
* allow a response. Only the application can respond to the notification by
38-
* overriding that handler in the |FlutterAppDelegate| subclass of the
39-
* application.
33+
* notification.
4034
*/
4135
- (void)handleDidFinishLaunching:(NSNotification*)notification;
4236

shell/platform/darwin/macos/framework/Headers/FlutterPluginMacOS.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
#import "FlutterCodecs.h"
1010
#import "FlutterMacros.h"
1111

12-
// TODO: Merge this file and the iOS version with FlutterPluginRegistrar.h and
13-
// with the iOS FlutterPlugin.h, sharing all but the platform-specific methods.
14-
1512
NS_ASSUME_NONNULL_BEGIN
1613

1714
@protocol FlutterPluginRegistrar;

shell/platform/darwin/macos/framework/Source/FlutterAppDelegate.mm

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,30 @@ - (void)applicationWillFinishLaunching:(NSNotification*)notification {
4242
[_lifecycleRegistrar handleWillFinishLaunching:notification];
4343
}
4444

45-
#define DISTRIBUTE_NOTIFICATION(SELECTOR) \
45+
// Using a macro to avoid errors where the selectors don't match.
46+
#ifdef FORWARD_NOTIFICATION
47+
#error FORWARD_NOTIFICATION ALREADY DEFINED!
48+
#endif
49+
#define FORWARD_NOTIFICATION(SELECTOR) \
4650
-(void)application##SELECTOR : (NSNotification*)notification { \
4751
[[self lifecycleRegistrar] handle##SELECTOR:notification]; \
4852
}
4953

50-
DISTRIBUTE_NOTIFICATION(DidFinishLaunching)
51-
DISTRIBUTE_NOTIFICATION(WillBecomeActive)
52-
DISTRIBUTE_NOTIFICATION(DidBecomeActive)
53-
DISTRIBUTE_NOTIFICATION(WillResignActive)
54-
DISTRIBUTE_NOTIFICATION(DidResignActive)
55-
DISTRIBUTE_NOTIFICATION(WillTerminate)
56-
DISTRIBUTE_NOTIFICATION(WillHide)
57-
DISTRIBUTE_NOTIFICATION(DidHide)
58-
DISTRIBUTE_NOTIFICATION(WillUnhide)
59-
DISTRIBUTE_NOTIFICATION(DidUnhide)
60-
DISTRIBUTE_NOTIFICATION(DidChangeScreenParameters)
61-
DISTRIBUTE_NOTIFICATION(DidChangeOcclusionState)
62-
63-
#undef DISTRIBUTE_NOTIFICATION
54+
// WillFinishLaunching is handled manually above.
55+
FORWARD_NOTIFICATION(DidFinishLaunching)
56+
FORWARD_NOTIFICATION(WillBecomeActive)
57+
FORWARD_NOTIFICATION(DidBecomeActive)
58+
FORWARD_NOTIFICATION(WillResignActive)
59+
FORWARD_NOTIFICATION(DidResignActive)
60+
FORWARD_NOTIFICATION(WillTerminate)
61+
FORWARD_NOTIFICATION(WillHide)
62+
FORWARD_NOTIFICATION(DidHide)
63+
FORWARD_NOTIFICATION(WillUnhide)
64+
FORWARD_NOTIFICATION(DidUnhide)
65+
FORWARD_NOTIFICATION(DidChangeScreenParameters)
66+
FORWARD_NOTIFICATION(DidChangeOcclusionState)
67+
68+
#undef FORWARD_NOTIFICATION
6469

6570
#pragma mark - Delegate handling
6671

shell/platform/darwin/macos/framework/Source/FlutterAppLifecycleDelegate.mm

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,31 @@ - (void)addObserverFor:(NSString*)name selector:(SEL)selector {
3535
- (instancetype)init {
3636
if (self = [super init]) {
3737
_notificationUnsubscribers = [[NSMutableArray alloc] init];
38-
[self addObserverFor:NSApplicationWillFinishLaunchingNotification
39-
selector:@selector(handleWillFinishLaunching:)];
40-
[self addObserverFor:NSApplicationDidFinishLaunchingNotification
41-
selector:@selector(handleDidFinishLaunching:)];
42-
[self addObserverFor:NSApplicationWillBecomeActiveNotification
43-
selector:@selector(handleWillBecomeActive:)];
44-
[self addObserverFor:NSApplicationDidBecomeActiveNotification
45-
selector:@selector(handleDidBecomeActive:)];
46-
[self addObserverFor:NSApplicationWillResignActiveNotification
47-
selector:@selector(handleWillResignActive:)];
48-
[self addObserverFor:NSApplicationDidResignActiveNotification
49-
selector:@selector(handleDidResignActive:)];
50-
[self addObserverFor:NSApplicationWillTerminateNotification
51-
selector:@selector(handleWillTerminate:)];
52-
[self addObserverFor:NSApplicationWillHideNotification selector:@selector(handleWillHide:)];
53-
[self addObserverFor:NSApplicationDidHideNotification selector:@selector(handleDidHide:)];
54-
[self addObserverFor:NSApplicationWillUnhideNotification selector:@selector(handleWillUnhide:)];
55-
[self addObserverFor:NSApplicationDidUnhideNotification selector:@selector(handleDidUnhide:)];
56-
[self addObserverFor:NSApplicationDidChangeOcclusionStateNotification
57-
selector:@selector(handleDidChangeOcclusionState:)];
58-
[self addObserverFor:NSApplicationDidChangeScreenParametersNotification
59-
selector:@selector(handleDidChangeScreenParameters:)];
38+
39+
// Using a macro to avoid errors where the notification doesn't match the
40+
// selector.
41+
#ifdef OBSERVE_NOTIFICATION
42+
#error OBSERVE_NOTIFICATION ALREADY DEFINED!
43+
#endif
44+
#define OBSERVE_NOTIFICATION(SELECTOR) \
45+
[self addObserverFor:NSApplication##SELECTOR##Notification selector:@selector(handle##SELECTOR:)]
46+
47+
OBSERVE_NOTIFICATION(WillFinishLaunching);
48+
OBSERVE_NOTIFICATION(DidFinishLaunching);
49+
OBSERVE_NOTIFICATION(WillBecomeActive);
50+
OBSERVE_NOTIFICATION(DidBecomeActive);
51+
OBSERVE_NOTIFICATION(WillResignActive);
52+
OBSERVE_NOTIFICATION(DidResignActive);
53+
OBSERVE_NOTIFICATION(WillTerminate);
54+
OBSERVE_NOTIFICATION(WillHide);
55+
OBSERVE_NOTIFICATION(DidHide);
56+
OBSERVE_NOTIFICATION(WillUnhide);
57+
OBSERVE_NOTIFICATION(DidUnhide);
58+
OBSERVE_NOTIFICATION(DidChangeScreenParameters);
59+
OBSERVE_NOTIFICATION(DidChangeOcclusionState);
60+
61+
#undef OBSERVE_NOTIFICATION
62+
6063
_delegates = [NSPointerArray weakObjectsPointerArray];
6164
}
6265
return self;
@@ -103,32 +106,34 @@ - (void)removeDelegate:(NSObject<FlutterAppLifecycleDelegate>*)delegate {
103106

104107
// This isn't done via performSelector because that can cause leaks due
105108
// to the selector not being known.
109+
#ifdef DISTRIBUTE_NOTIFICATION
110+
#error DISTRIBUTE_NOTIFICATION ALREADY DEFINED!
111+
#endif
106112
#define DISTRIBUTE_NOTIFICATION(SELECTOR) \
107113
-(void)SELECTOR : (NSNotification*)notification { \
108-
NSLog(@"Received " #SELECTOR " notification."); \
109114
for (NSObject<FlutterAppLifecycleDelegate> * delegate in _delegates) { \
110115
if (!delegate) { \
111116
continue; \
112117
} \
113-
if ([delegate respondsToSelector:@selector(SELECTOR:)]) { \
114-
[delegate SELECTOR:notification]; \
118+
if ([delegate respondsToSelector:@selector(handle##SELECTOR:)]) { \
119+
[delegate handle##SELECTOR:notification]; \
115120
} \
116121
} \
117122
}
118123

119-
DISTRIBUTE_NOTIFICATION(handleWillFinishLaunching)
120-
DISTRIBUTE_NOTIFICATION(handleDidFinishLaunching)
121-
DISTRIBUTE_NOTIFICATION(handleWillBecomeActive)
122-
DISTRIBUTE_NOTIFICATION(handleDidBecomeActive)
123-
DISTRIBUTE_NOTIFICATION(handleWillResignActive)
124-
DISTRIBUTE_NOTIFICATION(handleDidResignActive)
125-
DISTRIBUTE_NOTIFICATION(handleWillTerminate)
126-
DISTRIBUTE_NOTIFICATION(handleWillHide)
127-
DISTRIBUTE_NOTIFICATION(handleWillUnhide)
128-
DISTRIBUTE_NOTIFICATION(handleDidHide)
129-
DISTRIBUTE_NOTIFICATION(handleDidUnhide)
130-
DISTRIBUTE_NOTIFICATION(handleDidChangeScreenParameters)
131-
DISTRIBUTE_NOTIFICATION(handleDidChangeOcclusionState)
124+
DISTRIBUTE_NOTIFICATION(WillFinishLaunching)
125+
DISTRIBUTE_NOTIFICATION(DidFinishLaunching)
126+
DISTRIBUTE_NOTIFICATION(WillBecomeActive)
127+
DISTRIBUTE_NOTIFICATION(DidBecomeActive)
128+
DISTRIBUTE_NOTIFICATION(WillResignActive)
129+
DISTRIBUTE_NOTIFICATION(DidResignActive)
130+
DISTRIBUTE_NOTIFICATION(WillTerminate)
131+
DISTRIBUTE_NOTIFICATION(WillHide)
132+
DISTRIBUTE_NOTIFICATION(WillUnhide)
133+
DISTRIBUTE_NOTIFICATION(DidHide)
134+
DISTRIBUTE_NOTIFICATION(DidUnhide)
135+
DISTRIBUTE_NOTIFICATION(DidChangeScreenParameters)
136+
DISTRIBUTE_NOTIFICATION(DidChangeOcclusionState)
132137

133138
#undef DISTRIBUTE_NOTIFICATION
134139

shell/platform/darwin/macos/framework/Source/FlutterEngine.mm

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
NSString* const kFlutterPlatformChannel = @"flutter/platform";
3131
NSString* const kFlutterSettingsChannel = @"flutter/settings";
32+
NSString* const kFlutterLifecycleChannel = @"flutter/lifecycle";
33+
34+
// The size of the channel buffer for the lifecycle channel.
35+
NSUInteger const kLifecycleChannelBufferSize = 1000;
3236

3337
/**
3438
* Constructs and returns a FlutterLocale struct corresponding to |locale|, which must outlive
@@ -52,27 +56,6 @@ static FlutterLocale FlutterLocaleFromNSLocale(NSLocale* locale) {
5256
/// Clipboard plain text format.
5357
constexpr char kTextPlainFormat[] = "text/plain";
5458

55-
namespace {
56-
57-
std::string LifecycleStateToString(FlutterEngineLifecycleState state) {
58-
switch (state) {
59-
case kFlutterEngineLifecycleStateDetached:
60-
return "AppLifecycleState.detached";
61-
case kFlutterEngineLifecycleStateInitializing:
62-
return "AppLifecycleState.initializing";
63-
case kFlutterEngineLifecycleStateResumed:
64-
return "AppLifecycleState.resumed";
65-
case kFlutterEngineLifecycleStateInactive:
66-
return "AppLifecycleState.inactive";
67-
case kFlutterEngineLifecycleStateHidden:
68-
return "AppLifecycleState.hidden";
69-
case kFlutterEngineLifecycleStatePaused:
70-
return "AppLifecycleState.paused";
71-
}
72-
}
73-
74-
} // namespace
75-
7659
#pragma mark -
7760

7861
// Records an active handler of the messenger (FlutterEngine) that listens to
@@ -448,6 +431,11 @@ - (instancetype)initWithName:(NSString*)labelPrefix
448431
}
449432

450433
- (void)dealloc {
434+
FlutterAppDelegate* appDelegate =
435+
(FlutterAppDelegate*)[[FlutterApplication sharedApplication] delegate];
436+
if (appDelegate != nil) {
437+
[appDelegate removeApplicationLifecycleDelegate:self];
438+
}
451439
@synchronized(_isResponseValid) {
452440
[_isResponseValid removeAllObjects];
453441
[_isResponseValid addObject:@NO];
@@ -564,6 +552,14 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
564552
[self updateWindowMetricsForViewController:nextViewController];
565553
}
566554

555+
// Send a message to the lifecycle channel to bump up the channel buffer size
556+
// so that any lifecycle messages sent before the framework is listening
557+
// eventually get delivered.
558+
[[FlutterBasicMessageChannel messageChannelWithName:kFlutterLifecycleChannel
559+
binaryMessenger:self.binaryMessenger
560+
codec:[FlutterStandardMessageCodec sharedInstance]]
561+
resizeChannelBuffer:kLifecycleChannelBufferSize];
562+
567563
[self updateDisplayConfig];
568564
// Send the initial user settings such as brightness and text scale factor
569565
// to the engine.
@@ -1066,6 +1062,8 @@ - (void)setApplicationState:(FlutterEngineLifecycleState)state {
10661062
kFlutterEngineLifecycleStateResumed, kFlutterEngineLifecycleStateInactive,
10671063
kFlutterEngineLifecycleStateHidden, kFlutterEngineLifecycleStatePaused,
10681064
};
1065+
// Make sure that the given state exists in the state_order.
1066+
assert(std::find(state_order.begin(), state_order.end(), state) != state_order.end());
10691067

10701068
FlutterEngineLifecycleState previousState = _embedderAPI.GetLifecycleState(_engine);
10711069
// Make sure that when we transition between states, it follows the allowed
@@ -1082,22 +1080,15 @@ - (void)setApplicationState:(FlutterEngineLifecycleState)state {
10821080
}
10831081
}
10841082

1085-
NSLog(@"Moving to state %s from %s", LifecycleStateToString(state).c_str(),
1086-
LifecycleStateToString(previousState).c_str());
10871083
for (std::vector<FlutterEngineLifecycleState>::size_type i = 0; i < state_changes.size(); i++) {
1088-
NSLog(@"Sending application state change to %s",
1089-
LifecycleStateToString(state_changes[i]).c_str());
10901084
_embedderAPI.SetLifecycleState(_engine,
10911085
static_cast<FlutterEngineLifecycleState>(state_changes[i]));
10921086
}
10931087
}
10941088

10951089
/**
10961090
* Called when the |FlutterAppDelegate| gets the applicationWillFinishLaunching
1097-
* notification. This only notifies that the notification occurred, it doesn't
1098-
* allow a response. Only the application can respond to the notification by
1099-
* overriding that handler in the |FlutterAppDelegate| subclass of the
1100-
* application.
1091+
* notification.
11011092
*/
11021093
- (void)handleWillFinishLaunching:(NSNotification*)notification {
11031094
[self setApplicationState:kFlutterEngineLifecycleStateInitializing];
@@ -1136,15 +1127,13 @@ - (void)handleWillResignActive:(NSNotification*)notification {
11361127
- (void)handleDidChangeOcclusionState:(NSNotification*)notification API_AVAILABLE(macos(10.9)) {
11371128
NSApplicationOcclusionState occlusionState = [NSApp occlusionState];
11381129
if (occlusionState & NSApplicationOcclusionStateVisible) {
1139-
NSLog(@"Changing occlusion state to visible");
11401130
_visible = YES;
11411131
if (_active) {
11421132
[self setApplicationState:kFlutterEngineLifecycleStateResumed];
11431133
} else {
11441134
[self setApplicationState:kFlutterEngineLifecycleStateInactive];
11451135
}
11461136
} else {
1147-
NSLog(@"Changing occlusion state to invisible");
11481137
_visible = NO;
11491138
[self setApplicationState:kFlutterEngineLifecycleStateHidden];
11501139
}

shell/platform/embedder/embedder.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,9 @@ std::string LifecycleStateToString(FlutterEngineLifecycleState state) {
29592959
return "AppLifecycleState.hidden";
29602960
case kFlutterEngineLifecycleStatePaused:
29612961
return "AppLifecycleState.paused";
2962+
default:
2963+
assert(false && "Lifecycle state not recognized");
2964+
break;
29622965
}
29632966
}
29642967

shell/platform/embedder/embedder.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,7 +1958,7 @@ typedef struct {
19581958
/// allowed state machine:
19591959
///
19601960
/// +-----------+ +--------------+ +-----------+
1961-
/// | detached |<------>| initializing |<----->| resumed |
1961+
/// | detached |------->| initializing |------>| resumed |
19621962
/// +-----------+ +--------------+ +-----------+
19631963
/// ^ ^
19641964
/// | |
@@ -1969,25 +1969,29 @@ typedef struct {
19691969
///
19701970
/// The states and their meanings are as follows:
19711971
///
1972-
/// detached: The initial state of the state machine. On Android, also the final
1973-
/// state of the state machine. Other platforms do not enter this
1974-
/// state again after leaving it.
1972+
/// detached: The initial state of the state machine. On Android and iOS,
1973+
/// also the final state of the state machine when all views are
1974+
/// detached. Other platforms do not enter this state again after
1975+
/// initially leaving it.
19751976
///
1976-
/// initializing: The state entered once the engine is running, but before
1977+
/// initializing: The state entered once the engine is running, but before
19771978
/// drawing the first frame.
19781979
///
19791980
/// resumed: The nominal "running" state of the application. The
19801981
/// application is visible, has input focus, and is running.
19811982
///
1982-
/// inactive: At least some of the application is visible, but it
1983-
/// does not have input focus.
1983+
/// inactive: At least one view of the application is visible, but none
1984+
/// have input focus. The application is otherwise running
1985+
/// normally.
19841986
///
1985-
/// hidden: No part of the application is visible, and it does not have input
1986-
/// focus.
1987+
/// hidden: All views of an application are hidden, either because the
1988+
/// application is being stopped (on iOS and Android), or because
1989+
/// it is being minimized or on a desktop that is no longer visible
1990+
/// (on desktop), or on a tab that is no longer visible (on web).
19871991
///
1988-
/// paused: The application is not running, and can be detached or resumed at
1989-
/// any time. This state is typically only entered into on iOS and
1990-
/// Android.
1992+
/// paused: The application is not running, and can be detached or started
1993+
/// again at any time. This state is typically only entered into on
1994+
/// iOS and Android.
19911995
typedef enum {
19921996
kFlutterEngineLifecycleStateDetached = 0x0,
19931997
kFlutterEngineLifecycleStateInitializing = 0x1,

0 commit comments

Comments
 (0)