Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions shell/platform/darwin/macos/framework/Headers/FlutterDartProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ - (instancetype)initWithPrecompiledDartBundle:(NSBundle*)bundle {
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;
}

Expand Down
8 changes: 8 additions & 0 deletions shell/platform/darwin/macos/framework/Source/FlutterEngine.mm
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
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;
Expand All @@ -272,6 +277,9 @@ - (BOOL)runWithEntrypoint:(NSString*)entrypoint {
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),
Expand Down