-
Notifications
You must be signed in to change notification settings - Fork 6k
Build iOS and macOS Obj-C with -fapplication-extension flag #40332
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,10 @@ source_set("flutter_framework_source_arc") { | |
| cflags_objc = flutter_cflags_objc_arc | ||
| cflags_objcc = flutter_cflags_objcc_arc | ||
|
|
||
| defines = [ "FLUTTER_FRAMEWORK=1" ] | ||
| defines = [ | ||
| "FLUTTER_FRAMEWORK=1", | ||
| "APPLICATION_EXTENSION_API_ONLY=1", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, this would be set by a buildroot flag. |
||
| ] | ||
| allow_circular_includes_from = [ ":flutter_framework_source" ] | ||
| deps = [ | ||
| ":flutter_framework_source", | ||
|
|
@@ -153,7 +156,10 @@ source_set("flutter_framework_source") { | |
|
|
||
| sources += _flutter_framework_headers | ||
|
|
||
| defines = [ "FLUTTER_FRAMEWORK=1" ] | ||
| defines = [ | ||
| "FLUTTER_FRAMEWORK=1", | ||
| "APPLICATION_EXTENSION_API_ONLY=1", | ||
| ] | ||
|
|
||
| if (shell_enable_metal) { | ||
| sources += [ | ||
|
|
@@ -320,7 +326,10 @@ shared_library("create_flutter_framework_dylib") { | |
|
|
||
| output_name = "Flutter" | ||
|
|
||
| ldflags = [ "-Wl,-install_name,@rpath/Flutter.framework/Flutter" ] | ||
| ldflags = [ | ||
| "-Wl,-install_name,@rpath/Flutter.framework/Flutter", | ||
| "-fapplication-extension", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, behind a new flag, etc. |
||
| ] | ||
|
|
||
| public = _flutter_framework_headers | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -814,9 +814,14 @@ - (void)viewDidAppear:(BOOL)animated { | |
| if ([_engine.get() viewController] == self) { | ||
| [self onUserSettingsChanged:nil]; | ||
| [self onAccessibilityStatusChanged:nil]; | ||
|
|
||
| #if !APPLICATION_EXTENSION_API_ONLY | ||
| if (UIApplication.sharedApplication.applicationState == UIApplicationStateActive) { | ||
| #endif | ||
| [[_engine.get() lifecycleChannel] sendMessage:@"AppLifecycleState.resumed"]; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it possible to end up sending this if the whole process hosting the extension itself was in the background, thus UIApplication.sharedApplication.applicationState != UIApplicationStateActive if we had access to the sharedApplication? If we sent in "resumed" without checking, might be end up in an engine state where we continue to issue GPU commands while in the background and crash?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like a race that I bet could happen in the app extension #23175 |
||
| #if !APPLICATION_EXTENSION_API_ONLY | ||
| } | ||
| #endif | ||
| } | ||
| [super viewDidAppear:animated]; | ||
| } | ||
|
|
@@ -1304,8 +1309,13 @@ - (void)viewDidLayoutSubviews { | |
| // There is no guarantee that UIKit will layout subviews when the application is active. Creating | ||
| // the surface when inactive will cause GPU accesses from the background. Only wait for the first | ||
| // frame to render when the application is actually active. | ||
| bool applicationIsActive = | ||
| BOOL applicationIsActive = | ||
|
|
||
| #if APPLICATION_EXTENSION_API_ONLY | ||
| YES; | ||
| #else | ||
| [UIApplication sharedApplication].applicationState == UIApplicationStateActive; | ||
| #endif | ||
|
|
||
| // This must run after updateViewportMetrics so that the surface creation tasks are queued after | ||
| // the viewport metrics update tasks. | ||
|
|
@@ -1808,24 +1818,19 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences { | |
| _orientationPreferences = new_preferences; | ||
|
|
||
| if (@available(iOS 16.0, *)) { | ||
| #if APPLICATION_EXTENSION_API_ONLY | ||
| UIWindowScene* windowScene = self.viewIfLoaded.window.windowScene; | ||
| [self performOrientationUpdateOnWindowScene:windowScene]; | ||
| #else | ||
| for (UIScene* scene in UIApplication.sharedApplication.connectedScenes) { | ||
| if (![scene isKindOfClass:[UIWindowScene class]]) { | ||
| continue; | ||
| } | ||
| UIWindowScene* windowScene = (UIWindowScene*)scene; | ||
| UIWindowSceneGeometryPreferencesIOS* preference = | ||
| [[UIWindowSceneGeometryPreferencesIOS alloc] | ||
| initWithInterfaceOrientations:_orientationPreferences]; | ||
| [windowScene | ||
| requestGeometryUpdateWithPreferences:preference | ||
| errorHandler:^(NSError* error) { | ||
| os_log_error(OS_LOG_DEFAULT, | ||
| "Failed to change device orientation: %@", | ||
| error); | ||
| }]; | ||
| [self setNeedsUpdateOfSupportedInterfaceOrientations]; | ||
| [self performOrientationUpdateOnWindowScene:(UIWindowScene*)scene]; | ||
| } | ||
| #endif | ||
| } else { | ||
| #if !APPLICATION_EXTENSION_API_ONLY | ||
| UIInterfaceOrientationMask currentInterfaceOrientation = | ||
| 1 << [[UIApplication sharedApplication] statusBarOrientation]; | ||
| if (!(_orientationPreferences & currentInterfaceOrientation)) { | ||
|
|
@@ -1848,10 +1853,28 @@ - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences { | |
| forKey:@"orientation"]; | ||
| } | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
|
|
||
| - (void)performOrientationUpdateOnWindowScene:(UIWindowScene*)windowScene API_AVAILABLE(ios(16.0)) { | ||
| if (windowScene == nil) { | ||
| return; | ||
| } | ||
|
|
||
| UIWindowSceneGeometryPreferencesIOS* preference = [[UIWindowSceneGeometryPreferencesIOS alloc] | ||
| initWithInterfaceOrientations:_orientationPreferences]; | ||
| [windowScene | ||
| requestGeometryUpdateWithPreferences:preference | ||
| errorHandler:^(NSError* error) { | ||
| os_log_error(OS_LOG_DEFAULT, | ||
| "Failed to change device orientation: %@", error); | ||
| }]; | ||
| [self setNeedsUpdateOfSupportedInterfaceOrientations]; | ||
| [preference release]; | ||
| } | ||
|
|
||
| - (void)onHideHomeIndicatorNotification:(NSNotification*)notification { | ||
| self.isHomeIndicatorHidden = YES; | ||
| } | ||
|
|
@@ -1951,7 +1974,12 @@ - (void)onUserSettingsChanged:(NSNotification*)notification { | |
| } | ||
|
|
||
| - (CGFloat)textScaleFactor { | ||
| #if APPLICATION_EXTENSION_API_ONLY | ||
| UIContentSizeCategory category = | ||
| self.mainScreenIfViewLoaded.traitCollection.preferredContentSizeCategory; | ||
| #else | ||
| UIContentSizeCategory category = [UIApplication sharedApplication].preferredContentSizeCategory; | ||
| #endif | ||
| // The delta is computed by approximating Apple's typography guidelines: | ||
| // https://developer.apple.com/ios/human-interface-guidelines/visual-design/typography/ | ||
| // | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be set by a buildroot flag so the engine can be built with or without app extension safety. I put it here for testing.