63 bool hasExplicitBundle = bundle != nil;
68 auto settings = flutter::SettingsFromCommandLine(command_line,
true);
70 settings.task_observer_add = [](intptr_t key,
const fml::closure& callback) {
71 fml::TaskQueueId queue_id = fml::MessageLoop::GetCurrentTaskQueueId();
72 fml::MessageLoopTaskQueues::GetInstance()->AddTaskObserver(queue_id, key, callback);
76 settings.task_observer_remove = [](fml::TaskQueueId queue_id, intptr_t key) {
77 fml::MessageLoopTaskQueues::GetInstance()->RemoveTaskObserver(queue_id, key);
80 settings.log_message_callback = [](
const std::string& tag,
const std::string& message) {
81 std::stringstream stream;
83 stream << tag <<
": ";
86 std::string log = stream.str();
87 [FlutterLogger logDirect:[NSString stringWithUTF8String:log.c_str()]];
90 settings.enable_platform_isolates =
true;
96 if (settings.icu_data_path.empty()) {
97 NSString* icuDataPath = [engineBundle pathForResource:
@"icudtl" ofType:
@"dat"];
98 if (icuDataPath.length > 0) {
99 settings.icu_data_path = icuDataPath.UTF8String;
103 if (flutter::DartVM::IsRunningPrecompiledCode()) {
104 if (hasExplicitBundle) {
105 NSString* executablePath = bundle.executablePath;
106 if ([[NSFileManager defaultManager] fileExistsAtPath:executablePath]) {
107 settings.application_library_paths.push_back(executablePath.UTF8String);
112 if (settings.application_library_paths.empty()) {
113 NSString* libraryName = [mainBundle objectForInfoDictionaryKey:
@"FLTLibraryPath"];
114 NSString* libraryPath = [mainBundle pathForResource:libraryName ofType:
@""];
115 if (libraryPath.length > 0) {
116 NSString* executablePath = [NSBundle bundleWithPath:libraryPath].executablePath;
117 if (executablePath.length > 0) {
118 settings.application_library_paths.push_back(executablePath.UTF8String);
125 if (settings.application_library_paths.empty()) {
126 NSString* applicationFrameworkPath = [mainBundle pathForResource:
@"Frameworks/App.framework"
128 if (applicationFrameworkPath.length > 0) {
129 NSString* executablePath =
130 [NSBundle bundleWithPath:applicationFrameworkPath].executablePath;
131 if (executablePath.length > 0) {
132 settings.application_library_paths.push_back(executablePath.UTF8String);
139 if (settings.assets_path.empty()) {
142 if (assetsPath.length == 0) {
143 NSLog(
@"Failed to find assets path for \"%@\
"", bundle);
145 settings.assets_path = assetsPath.UTF8String;
150 if (!flutter::DartVM::IsRunningPrecompiledCode()) {
151 NSURL* applicationKernelSnapshotURL =
153 relativeToURL:[NSURL fileURLWithPath:assetsPath]];
155 if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&error]) {
156 settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;
158 NSLog(
@"Failed to find snapshot at %@: %@", applicationKernelSnapshotURL.path, error);
167 settings.may_insecurely_connect_to_all_domains =
true;
168 settings.domain_network_policy =
"";
171 #if TARGET_OS_SIMULATOR
174 settings.enable_wide_gamut =
false;
179 BOOL enableWideGamut =
181 settings.enable_wide_gamut = enableWideGamut;
184 NSNumber* nsAntialiasLines = [mainBundle objectForInfoDictionaryKey:
@"FLTAntialiasLines"];
185 settings.impeller_antialiased_lines = (nsAntialiasLines ? nsAntialiasLines.boolValue : NO);
187 settings.warn_on_impeller_opt_out =
true;
189 NSNumber* nsEnableSDFs = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableSDFs"];
190 settings.impeller_use_sdfs = (nsEnableSDFs ? nsEnableSDFs.boolValue : NO);
192 NSNumber* enableTraceSystrace = [mainBundle objectForInfoDictionaryKey:
@"FLTTraceSystrace"];
194 if (enableTraceSystrace != nil) {
195 settings.trace_systrace = enableTraceSystrace.boolValue;
198 NSNumber* profileMicrotasks = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileMicrotasks"];
200 if (profileMicrotasks != nil) {
201 settings.profile_microtasks = profileMicrotasks.boolValue;
204 NSNumber* enableDartAsserts = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartAsserts"];
205 if (enableDartAsserts != nil) {
206 settings.dart_flags.push_back(
"--enable-asserts");
209 NSNumber* enableDartProfiling = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableDartProfiling"];
211 if (enableDartProfiling != nil) {
212 settings.enable_dart_profiling = enableDartProfiling.boolValue;
215 NSNumber* profileStartup = [mainBundle objectForInfoDictionaryKey:
@"FLTProfileStartup"];
217 if (profileStartup != nil) {
218 settings.profile_startup = profileStartup.boolValue;
222 NSNumber* leakDartVM = [mainBundle objectForInfoDictionaryKey:
@"FLTLeakDartVM"];
224 if (leakDartVM != nil) {
225 settings.leak_vm = leakDartVM.boolValue;
228 NSNumber* enableMergedPlatformUIThread =
229 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableMergedPlatformUIThread"];
230 if (enableMergedPlatformUIThread != nil) {
231 FML_CHECK(enableMergedPlatformUIThread.boolValue)
232 <<
"FLTEnableMergedPlatformUIThread=false is no longer allowed.";
235 NSNumber* enableFlutterGPU = [mainBundle objectForInfoDictionaryKey:
@"FLTEnableFlutterGPU"];
236 if (enableFlutterGPU != nil) {
237 settings.enable_flutter_gpu = enableFlutterGPU.boolValue;
240 #if FLUTTER_RUNTIME_MODE == FLUTTER_RUNTIME_MODE_DEBUG
243 auto make_mapping_callback = [](
const uint8_t* mapping,
size_t size) {
244 return [mapping, size]() {
return std::make_unique<fml::NonOwnedMapping>(mapping, size); };
247 settings.dart_library_sources_kernel =
257 if (settings.old_gen_heap_size <= 0) {
258 settings.old_gen_heap_size = std::round([NSProcessInfo processInfo].physicalMemory * .48 /
259 flutter::kMegaByteSizeInBytes);
264 CGFloat scale = [UIScreen mainScreen].scale;
265 CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width * scale;
266 CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height * scale;
267 settings.resource_cache_max_bytes_threshold = screenWidth * screenHeight * 12 * 4;
270 NSNumber* enable_embedder_api =
271 [mainBundle objectForInfoDictionaryKey:
@"FLTEnableIOSEmbedderAPI"];
273 if (enable_embedder_api) {
274 settings.enable_embedder_api = enable_embedder_api.boolValue;
NSNumber *_Nullable FLTEnableWideGamutFromBundle(NSBundle *_Nullable bundle, NSBundle *_Nullable mainBundle)
static const char * kApplicationKernelSnapshotFileName
const intptr_t kPlatformStrongDillSize
FLUTTER_ASSERT_ARC const uint8_t kPlatformStrongDill[]
static BOOL DoesHardwareSupportWideGamut()
NSBundle * FLTGetApplicationBundle()
NSBundle * FLTFrameworkBundleWithIdentifier(NSString *flutterFrameworkBundleID)
NSString * FLTAssetsPathFromBundle(NSBundle *bundle)
fml::CommandLine CommandLineFromNSProcessInfo(NSProcessInfo *processInfoOrNil=nil)