From fc0da29cee477596b981efa33fe175ad9d52929e Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 20 Sep 2019 08:45:21 -0700 Subject: [PATCH 1/4] Added a default entrypoint variable to match android syntax. --- .../ios/framework/Headers/FlutterEngine.h | 22 ++++++++++++------- .../ios/framework/Source/FlutterEngine.mm | 2 ++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index ce0385f6672fb..da6c7b4221587 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -18,6 +18,12 @@ NS_ASSUME_NONNULL_BEGIN +/** + * The dart entrypoint that is associated with `main()`. This is to be used as an argument to the + * `runWithEntrypoint*` methods. + */ +extern NSString* const FlutterDefaultDartEntryPoint; + /** * The FlutterEngine class coordinates a single instance of execution for a * `FlutterDartProject`. It may have zero or one `FlutterViewController` at a @@ -99,10 +105,10 @@ FLUTTER_EXPORT * immediately. * * @param entrypoint The name of a top-level function from the same Dart - * library that contains the app's main() function. If this is nil, it will - * default to `main()`. If it is not the app's main() function, that function - * must be decorated with `@pragma(vm:entry-point)` to ensure the method is not - * tree-shaken by the Dart compiler. + * library that contains the app's main() function. If this is FlutterDefaultDartEntryPoint (or + * nil) it will default to `main()`. If it is not the app's main() function, that function must + * be decorated with `@pragma(vm:entry-point)` to ensure the method is not tree-shaken by the Dart + * compiler. * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. */ - (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint; @@ -114,10 +120,10 @@ FLUTTER_EXPORT * The first call to this method will create a new Isolate. Subsequent calls will return * immediately. * - * @param entrypoint The name of a top-level function from a Dart library. If nil, this will - * default to `main()`. If it is not the app's main() function, that function - * must be decorated with `@pragma(vm:entry-point)` to ensure the method is not - * tree-shaken by the Dart compiler. + * @param entrypoint The name of a top-level function from a Dart library. If this is + * FlutterDefaultDartEntryPoint (or nil); this will default to `main()`. If it is not the app's + * main() function, that function must be decorated with `@pragma(vm:entry-point)` to ensure the + * method is not tree-shaken by the Dart compiler. * @param uri The URI of the Dart library which contains the entrypoint method. IF nil, * this will default to the same library as the `main()` function in the Dart program. * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index b2374fa0d147c..acd8e53d70c3b 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -27,6 +27,8 @@ #import "flutter/shell/platform/darwin/ios/ios_surface.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" +NSString* const FlutterDefaultDartEntryPoint = nil; + @interface FlutterEngine () // Maintains a dictionary of plugin names that have registered with the engine. Used by // FlutterEngineRegistrar to implement a FlutterPluginRegistrar. From bc34054b7f342248937fbb896d89a6b1715bf18b Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 20 Sep 2019 08:48:26 -0700 Subject: [PATCH 2/4] Fixed camel case --- shell/platform/darwin/ios/framework/Headers/FlutterEngine.h | 2 +- shell/platform/darwin/ios/framework/Source/FlutterEngine.mm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index da6c7b4221587..2a1503ae2f79b 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN * The dart entrypoint that is associated with `main()`. This is to be used as an argument to the * `runWithEntrypoint*` methods. */ -extern NSString* const FlutterDefaultDartEntryPoint; +extern NSString* const FlutterDefaultDartEntrypoint; /** * The FlutterEngine class coordinates a single instance of execution for a diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index acd8e53d70c3b..6af366c863b4f 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -27,7 +27,7 @@ #import "flutter/shell/platform/darwin/ios/ios_surface.h" #import "flutter/shell/platform/darwin/ios/platform_view_ios.h" -NSString* const FlutterDefaultDartEntryPoint = nil; +NSString* const FlutterDefaultDartEntrypoint = nil; @interface FlutterEngine () // Maintains a dictionary of plugin names that have registered with the engine. Used by From ad2cf30667043fdb16135ca652a5d5e851e7b9f6 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Fri, 20 Sep 2019 08:51:04 -0700 Subject: [PATCH 3/4] fixed camel case in docstring --- shell/platform/darwin/ios/framework/Headers/FlutterEngine.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 2a1503ae2f79b..9e9311b8bbb82 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -105,7 +105,7 @@ FLUTTER_EXPORT * immediately. * * @param entrypoint The name of a top-level function from the same Dart - * library that contains the app's main() function. If this is FlutterDefaultDartEntryPoint (or + * library that contains the app's main() function. If this is FlutterDefaultDartEntrypoint (or * nil) it will default to `main()`. If it is not the app's main() function, that function must * be decorated with `@pragma(vm:entry-point)` to ensure the method is not tree-shaken by the Dart * compiler. @@ -121,7 +121,7 @@ FLUTTER_EXPORT * immediately. * * @param entrypoint The name of a top-level function from a Dart library. If this is - * FlutterDefaultDartEntryPoint (or nil); this will default to `main()`. If it is not the app's + * FlutterDefaultDartEntrypoint (or nil); this will default to `main()`. If it is not the app's * main() function, that function must be decorated with `@pragma(vm:entry-point)` to ensure the * method is not tree-shaken by the Dart compiler. * @param uri The URI of the Dart library which contains the entrypoint method. IF nil, From 1c5de8d8538298d58eeef7b1bf0715b8e73311a5 Mon Sep 17 00:00:00 2001 From: Aaron Clarke Date: Wed, 25 Sep 2019 16:03:34 -0700 Subject: [PATCH 4/4] I added `run` to and `initWithName:` to FlutterEngine. --- .../ios/framework/Headers/FlutterEngine.h | 31 +++++++++++++++++++ .../ios/framework/Source/FlutterEngine.mm | 8 +++++ 2 files changed, 39 insertions(+) diff --git a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h index 9e9311b8bbb82..193a9cc8e8be7 100644 --- a/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h +++ b/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h @@ -47,6 +47,26 @@ extern NSString* const FlutterDefaultDartEntrypoint; */ FLUTTER_EXPORT @interface FlutterEngine : NSObject + +/** + * Initialize this FlutterEngine. + * + * The engine will execute the project located in the bundle with the identifier + * "io.flutter.flutter.app" (the default for Flutter projects). + * + * A newly initialized engine will not run until either `-runWithEntrypoint:` or + * `-runWithEntrypoint:libraryURI:` is called. + * + * FlutterEngine created with this method will have allowHeadlessExecution set to `YES`. + * This means that the engine will continue to run regardless of whether a `FlutterViewController` + * is attached to it or not, until `-destroyContext:` is called or the process finishes. + * + * @param labelPrefix The label prefix used to identify threads for this instance. Should + * be unique across FlutterEngine instances, and is used in instrumentation to label + * the threads used by this FlutterEngine. + */ +- (instancetype)initWithName:(NSString*)labelPrefix; + /** * Initialize this FlutterEngine with a `FlutterDartProject`. * @@ -97,6 +117,17 @@ FLUTTER_EXPORT + (instancetype)new NS_UNAVAILABLE; +/** + * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that + * contains `main()`), using `main()` as the entrypoint (the default for Flutter projects). + * + * The first call to this method will create a new Isolate. Subsequent calls will return + * immediately. + * + * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. + */ +- (BOOL)run; + /** * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that * contains `main()`). diff --git a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm index 6af366c863b4f..2cfbbdb4849dc 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterEngine.mm @@ -72,6 +72,10 @@ @implementation FlutterEngine { FlutterBinaryMessengerRelay* _binaryMessenger; } +- (instancetype)initWithName:(NSString*)labelPrefix { + return [self initWithName:labelPrefix project:nil allowHeadlessExecution:YES]; +} + - (instancetype)initWithName:(NSString*)labelPrefix project:(FlutterDartProject*)project { return [self initWithName:labelPrefix project:project allowHeadlessExecution:YES]; } @@ -431,6 +435,10 @@ - (BOOL)createShell:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { return _shell != nullptr; } +- (BOOL)run { + return [self runWithEntrypoint:FlutterDefaultDartEntrypoint libraryURI:nil]; +} + - (BOOL)runWithEntrypoint:(NSString*)entrypoint libraryURI:(NSString*)libraryURI { if ([self createShell:entrypoint libraryURI:libraryURI]) { [self launchEngine:entrypoint libraryURI:libraryURI];