mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Add plumbing to grab dart entrypoint args on macOS (#21789)
This commit is contained in:
parent
9b752790f4
commit
04bf8791fe
@ -36,6 +36,16 @@ FLUTTER_EXPORT
|
||||
*/
|
||||
@property(nonatomic) bool enableMirrors;
|
||||
|
||||
/**
|
||||
* An NSArray of NSStrings to be passed as command line arguments to the Dart entrypoint.
|
||||
*
|
||||
* If this is not explicitly set, this will default to the contents of
|
||||
* [NSProcessInfo arguments], without the binary name.
|
||||
*
|
||||
* Set this to nil to pass no arguments to the Dart entrypoint.
|
||||
*/
|
||||
@property(nonatomic, nullable) NSArray<NSString*>* dartEntrypointArguments;
|
||||
|
||||
@end
|
||||
|
||||
#endif // FLUTTER_FLUTTERDARTPROJECT_H_
|
||||
|
||||
@ -27,6 +27,10 @@ static NSString* const kAppBundleIdentifier = @"io.flutter.flutter.app";
|
||||
NSAssert(self, @"Super init cannot be nil");
|
||||
|
||||
_dartBundle = bundle ?: [NSBundle bundleWithIdentifier:kAppBundleIdentifier];
|
||||
_dartEntrypointArguments = [[NSProcessInfo processInfo] arguments];
|
||||
// Remove the first element as it's the binary name
|
||||
_dartEntrypointArguments = [_dartEntrypointArguments
|
||||
subarrayWithRange:NSMakeRange(1, _dartEntrypointArguments.count - 1)];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@ -263,6 +263,11 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
std::transform(switches.begin(), switches.end(), std::back_inserter(argv),
|
||||
[](const std::string& arg) -> const char* { return arg.c_str(); });
|
||||
|
||||
std::vector<const char*> dartEntrypointArgs;
|
||||
for (NSString* argument in [_project dartEntrypointArguments]) {
|
||||
dartEntrypointArgs.push_back([argument UTF8String]);
|
||||
}
|
||||
|
||||
FlutterProjectArgs flutterArguments = {};
|
||||
flutterArguments.struct_size = sizeof(FlutterProjectArgs);
|
||||
flutterArguments.assets_path = _project.assetsPath.UTF8String;
|
||||
@ -272,6 +277,9 @@ static bool OnAcquireExternalTexture(FlutterEngine* engine,
|
||||
flutterArguments.platform_message_callback = (FlutterPlatformMessageCallback)OnPlatformMessage;
|
||||
flutterArguments.custom_dart_entrypoint = entrypoint.UTF8String;
|
||||
flutterArguments.shutdown_dart_vm_when_done = true;
|
||||
flutterArguments.dart_entrypoint_argc = dartEntrypointArgs.size();
|
||||
flutterArguments.dart_entrypoint_argv = dartEntrypointArgs.data();
|
||||
|
||||
static size_t sTaskRunnerIdentifiers = 0;
|
||||
const FlutterTaskRunnerDescription cocoa_task_runner_description = {
|
||||
.struct_size = sizeof(FlutterTaskRunnerDescription),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user