1 // Copyright 2013 The Flutter Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef FLUTTER_FLUTTERENGINE_H_ 6 #define FLUTTER_FLUTTERENGINE_H_ 7 8 #import <Foundation/Foundation.h> 9 10 #include "FlutterBinaryMessenger.h" 11 #include "FlutterDartProject.h" 12 #include "FlutterMacros.h" 13 #include "FlutterPluginRegistrarMacOS.h" 14 15 // TODO: Merge this file with the iOS FlutterEngine.h. 16 17 @class FlutterViewController; 18 19 /** 20 * Coordinates a single instance of execution of a Flutter engine. 21 */ 22 FLUTTER_EXPORT 23 @interface FlutterEngine : NSObject <FlutterPluginRegistry> 24 25 /** 26 * Initializes an engine with the given viewController. 27 * 28 * @param labelPrefix Currently unused; in the future, may be used for labelling threads 29 * as with the iOS FlutterEngine. 30 * @param project The project configuration. If nil, a default FlutterDartProject will be used. 31 */ 32 - (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix 33 project:(nullable FlutterDartProject*)project; 34 35 /** 36 * Initializes an engine with the given viewController. 37 * 38 * @param labelPrefix Currently unused; in the future, may be used for labelling threads 39 * as with the iOS FlutterEngine. 40 * @param project The project configuration. If nil, a default FlutterDartProject will be used. 41 */ 42 - (nonnull instancetype)initWithName:(nonnull NSString*)labelPrefix 43 project:(nullable FlutterDartProject*)project 44 allowHeadlessExecution:(BOOL)allowHeadlessExecution NS_DESIGNATED_INITIALIZER; 45 46 - (nonnull instancetype)init NS_UNAVAILABLE; 47 48 /** 49 * Runs a Dart program on an Isolate from the main Dart library (i.e. the library that 50 * contains `main()`). 51 * 52 * The first call to this method will create a new Isolate. Subsequent calls will return 53 * immediately. 54 * 55 * @param entrypoint The name of a top-level function from the same Dart 56 * library that contains the app's main() function. If this is nil, it will 57 * default to `main()`. If it is not the app's main() function, that function 58 * must be decorated with `@pragma(vm:entry-point)` to ensure the method is not 59 * tree-shaken by the Dart compiler. 60 * @return YES if the call succeeds in creating and running a Flutter Engine instance; NO otherwise. 61 */ 62 - (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint; 63 64 /** 65 * The `FlutterViewController` associated with this engine, if any. 66 */ 67 @property(nonatomic, nullable, weak) FlutterViewController* viewController; 68 69 /** 70 * The `FlutterBinaryMessenger` for communicating with this engine. 71 */ 72 @property(nonatomic, nonnull, readonly) id<FlutterBinaryMessenger> binaryMessenger; 73 74 @end 75 76 #endif // FLUTTER_FLUTTERENGINE_H_ 77