From a71e66131c4e90c3c7800da8c67071b3264ad2b2 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Tue, 6 Nov 2018 16:11:41 -0800 Subject: [PATCH 1/3] fix setInitialRoute --- .gitignore | 1 + .../darwin/ios/framework/Source/FlutterEngine.mm | 9 ++++++++- .../ios/framework/Source/FlutterEngine_Internal.h | 2 ++ .../ios/framework/Source/FlutterViewController.mm | 12 ++++++++++-- 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 730c7e4ce18fb..870f951370586 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,4 @@ tags Thumbs.db .idea pubspec.lock +.vscode/ diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 33ca6477bd06a..760c84f256511 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -264,7 +264,7 @@ - (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil { })); } -- (bool)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { +- (bool)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { if (_shell != nullptr) { FML_LOG(WARNING) << "This FlutterEngine was already invoked."; return false; @@ -351,6 +351,13 @@ - (bool)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI << entrypoint.UTF8String; } else { [self maybeSetupPlatformViewChannels]; + } + + return _shell != nullptr; +} + +- (bool)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { + if ([self createShell:entrypoint libraryURI:libraryURI]) { [self launchEngine:entrypoint libraryURI:libraryURI]; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h index 86d1fc736eb32..abc05ec2b70ca 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h @@ -42,6 +42,8 @@ - (shell::FlutterPlatformViewsController*)platformViewsController; - (FlutterTextInputPlugin*)textInputPlugin; - (void)launchEngine:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil; +- (bool)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryOrNil; + @end diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 9c160cef29034..5ce634383bcaf 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -37,6 +37,7 @@ @implementation FlutterViewController { blink::ViewportMetrics _viewportMetrics; BOOL _initialized; BOOL _viewOpaque; + BOOL _engineNeedsLaunch; } #pragma mark - Manage and override all designated initializers @@ -49,6 +50,7 @@ - (instancetype)initWithEngine:(FlutterEngine*)engine if (self) { _viewOpaque = YES; _engine.reset([engine retain]); + _engineNeedsLaunch = false; _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); _weakFactory = std::make_unique>(self); @@ -68,8 +70,8 @@ - (instancetype)initWithProject:(FlutterDartProject*)projectOrNil _weakFactory = std::make_unique>(self); _engine.reset([[FlutterEngine alloc] initWithName:@"io.flutter" project:projectOrNil]); _flutterView.reset([[FlutterView alloc] initWithDelegate:_engine opaque:self.isViewOpaque]); - [_engine.get() runWithEntrypoint:nil]; - [_engine.get() setViewController:self]; + [_engine.get() createShell:nil libraryURI:nil]; + _engineNeedsLaunch = true; [self performCommonViewControllerInitialization]; } @@ -371,6 +373,12 @@ - (void)surfaceUpdated:(BOOL)appeared { - (void)viewWillAppear:(BOOL)animated { TRACE_EVENT0("flutter", "viewWillAppear"); + if (_engineNeedsLaunch) { + [_engine.get() launchEngine:nil libraryURI:nil]; + [_engine.get() setViewController:self]; + _engineNeedsLaunch = false; + } + // Only recreate surface on subsequent appearances when viewport metrics are known. // First time surface creation is done on viewDidLayoutSubviews. if (_viewportMetrics.physical_width) From c27fbaaa83c9ffc9449a41e4dd6d6d8f82a05eb3 Mon Sep 17 00:00:00 2001 From: Dan Field Date: Wed, 7 Nov 2018 17:04:08 -0800 Subject: [PATCH 2/3] Don't block the platfrorm thread --- .../Source/FlutterObservatoryPublisher.mm | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm index 73490540a61b9..8ace61c8e2adc 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm @@ -67,7 +67,7 @@ - (instancetype)init { return self; } -- (void)dealloc { +- (void)stopService { #if TARGET_IPHONE_SIMULATOR if (_dnsServiceRef) { DNSServiceRefDeallocate(_dnsServiceRef); @@ -76,20 +76,17 @@ - (void)dealloc { #else // TARGET_IPHONE_SIMULATOR [_netService.get() stop]; #endif // TARGET_IPHONE_SIMULATOR +} + +- (void)dealloc { + [self stopService]; blink::DartServiceIsolate::RemoveServerStatusCallback(std::move(_callbackHandle)); [super dealloc]; } - (void)publishServiceProtocolPort:(std::string)uri { -#if TARGET_IPHONE_SIMULATOR - if (_dnsServiceRef) { - DNSServiceRefDeallocate(_dnsServiceRef); - _dnsServiceRef = NULL; - } -#else // TARGET_IPHONE_SIMULATOR - [_netService.get() stop]; -#endif // TARGET_IPHONE_SIMULATOR + [self stopService]; if (uri.empty()) { return; } @@ -115,7 +112,7 @@ - (void)publishServiceProtocolPort:(std::string)uri { if (err != 0) { FML_LOG(ERROR) << "Failed to register observatory port with mDNS."; } else { - DNSServiceProcessResult(_dnsServiceRef); + DNSServiceSetDispatchQueue(_dnsServiceRef, [NSOperationQueue currentQueue].underlyingQueue); } #else // TARGET_IPHONE_SIMULATOR _netService.reset([[NSNetService alloc] initWithDomain:@"local." @@ -128,7 +125,7 @@ - (void)publishServiceProtocolPort:(std::string)uri { } - (void)netServiceDidPublish:(NSNetService*)sender { - FML_LOG(INFO) << "FlutterObservatoryPublisher is ready!"; + FML_DLOG(INFO) << "FlutterObservatoryPublisher is ready!"; } - (void)netService:(NSNetService*)sender didNotPublish:(NSDictionary*)errorDict { From 5834433c9f4cfe04b8403cbd7d45811f49b675ea Mon Sep 17 00:00:00 2001 From: Dan Field Date: Thu, 8 Nov 2018 10:09:26 -0800 Subject: [PATCH 3/3] merge and nit --- .../darwin/ios/framework/Source/FlutterObservatoryPublisher.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm index 90a73c72cf9d6..980bec0854e7f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterObservatoryPublisher.mm @@ -112,7 +112,7 @@ - (void)publishServiceProtocolPort:(std::string)uri { if (err != 0) { FML_LOG(ERROR) << "Failed to register observatory port with mDNS."; } else { - DNSServiceSetDispatchQueue(_dnsServiceRef, [NSOperationQueue currentQueue].underlyingQueue); + DNSServiceSetDispatchQueue(_dnsServiceRef, dispatch_get_main_queue()); } #else // TARGET_IPHONE_SIMULATOR _netService.reset([[NSNetService alloc] initWithDomain:@"local."