19
19
static const char * kVMKernelSnapshotFileName = " platform.dill" ;
20
20
static const char * kApplicationKernelSnapshotFileName = " kernel_blob.bin" ;
21
21
22
- static blink::Settings DefaultSettingsForProcess () {
22
+ static blink::Settings DefaultSettingsForProcess (NSBundle * bundle = nil ) {
23
23
auto command_line = shell::CommandLineFromNSProcessInfo ();
24
24
25
- // Settings passed in explicitly via command line arguments take priority.
25
+ // Precedence:
26
+ // 1. Settings from the specified NSBundle.
27
+ // 2. Settings passed explicitly via command-line arguments.
28
+ // 3. Settings from the NSBundle with the default bundle ID.
29
+ // 4. Settings from the main NSBundle and default values.
30
+
31
+ NSBundle * mainBundle = [NSBundle mainBundle ];
32
+ NSBundle * engineBundle = [NSBundle bundleForClass: [FlutterViewController class ]];
33
+
34
+ bool hasExplicitBundle = bundle != nil ;
35
+ if (bundle == nil ) {
36
+ bundle = [NSBundle bundleWithIdentifier: [FlutterDartProject defaultBundleIdentifier ]];
37
+ }
38
+ if (bundle == nil ) {
39
+ bundle = mainBundle;
40
+ }
41
+
26
42
auto settings = shell::SettingsFromCommandLine (command_line);
27
43
28
44
settings.task_observer_add = [](intptr_t key, fml::closure callback) {
38
54
39
55
// Flutter ships the ICU data file in the the bundle of the engine. Look for it there.
40
56
if (settings.icu_data_path .size () == 0 ) {
41
- NSBundle * bundle = [NSBundle bundleForClass: [FlutterViewController class ]];
42
- NSString * icuDataPath = [bundle pathForResource: @" icudtl" ofType: @" dat" ];
57
+ NSString * icuDataPath = [engineBundle pathForResource: @" icudtl" ofType: @" dat" ];
43
58
if (icuDataPath.length > 0 ) {
44
59
settings.icu_data_path = icuDataPath.UTF8String ;
45
60
}
46
61
}
47
62
48
63
if (blink::DartVM::IsRunningPrecompiledCode ()) {
49
- // The application bundle could be specified in the Info.plist.
64
+ if (hasExplicitBundle) {
65
+ NSString * executablePath = bundle.executablePath ;
66
+ if ([[NSFileManager defaultManager ] fileExistsAtPath: executablePath]) {
67
+ settings.application_library_path = executablePath.UTF8String ;
68
+ }
69
+ }
70
+
71
+ // No application bundle specified. Try a known location from the main bundle's Info.plist.
50
72
if (settings.application_library_path .size () == 0 ) {
51
- NSString * libraryName = [[ NSBundle mainBundle ] objectForInfoDictionaryKey: @" FLTLibraryPath" ];
52
- NSString * libraryPath = [[ NSBundle mainBundle ] pathForResource: libraryName ofType: nil ];
73
+ NSString * libraryName = [mainBundle objectForInfoDictionaryKey: @" FLTLibraryPath" ];
74
+ NSString * libraryPath = [mainBundle pathForResource: libraryName ofType: @" " ];
53
75
if (libraryPath.length > 0 ) {
54
76
settings.application_library_path =
55
77
[NSBundle bundleWithPath: libraryPath].executablePath .UTF8String ;
60
82
// Frameworks directory.
61
83
if (settings.application_library_path .size () == 0 ) {
62
84
NSString * applicationFrameworkPath =
63
- [[ NSBundle mainBundle ] pathForResource: @" Frameworks/App.framework" ofType: @" " ];
85
+ [mainBundle pathForResource: @" Frameworks/App.framework" ofType: @" " ];
64
86
if (applicationFrameworkPath.length > 0 ) {
65
87
settings.application_library_path =
66
88
[NSBundle bundleWithPath: applicationFrameworkPath].executablePath .UTF8String ;
70
92
71
93
// Checks to see if the flutter assets directory is already present.
72
94
if (settings.assets_path .size () == 0 ) {
73
- // The kernel assets will not be present in the Flutter frameworks bundle since it is not user
74
- // editable. Instead, look inside the main bundle.
75
- NSBundle * bundle = [NSBundle mainBundle ];
76
- NSString * assets_directory_name = [FlutterDartProject flutterAssetsName: bundle];
77
- NSString * assetsPath = [bundle pathForResource: assets_directory_name ofType: @" " ];
95
+ NSString * assetsName = [FlutterDartProject flutterAssetsName: bundle];
96
+ NSString * assetsPath = [mainBundle pathForResource: assetsName ofType: @" " ];
78
97
79
98
if (assetsPath.length > 0 ) {
80
99
settings.assets_path = assetsPath.UTF8String ;
@@ -136,15 +155,7 @@ - (instancetype)initWithPrecompiledDartBundle:(NSBundle*)bundle {
136
155
137
156
if (self) {
138
157
_precompiledDartBundle.reset ([bundle retain ]);
139
-
140
- _settings = DefaultSettingsForProcess ();
141
-
142
- if (bundle != nil ) {
143
- NSString * executablePath = _precompiledDartBundle.get ().executablePath ;
144
- if ([[NSFileManager defaultManager ] fileExistsAtPath: executablePath]) {
145
- _settings.application_library_path = executablePath.UTF8String ;
146
- }
147
- }
158
+ _settings = DefaultSettingsForProcess (bundle);
148
159
}
149
160
150
161
return self;
@@ -218,11 +229,6 @@ + (NSString*)flutterAssetsName:(NSBundle*)bundle {
218
229
return flutterAssetsName;
219
230
}
220
231
221
- + (NSString *)pathForFlutterAssetsFromBundle : (NSBundle *)bundle {
222
- NSString * flutterAssetsName = [FlutterDartProject flutterAssetsName: bundle];
223
- return [bundle pathForResource: flutterAssetsName ofType: nil ];
224
- }
225
-
226
232
+ (NSString *)lookupKeyForAsset : (NSString *)asset {
227
233
NSString * flutterAssetsName = [FlutterDartProject flutterAssetsName: [NSBundle mainBundle ]];
228
234
return [NSString stringWithFormat: @" %@ /%@ " , flutterAssetsName, asset];
@@ -232,4 +238,8 @@ + (NSString*)lookupKeyForAsset:(NSString*)asset fromPackage:(NSString*)package {
232
238
return [self lookupKeyForAsset: [NSString stringWithFormat: @" packages/%@ /%@ " , package, asset]];
233
239
}
234
240
241
+ + (NSString *)defaultBundleIdentifier {
242
+ return @" io.flutter.flutter.app" ;
243
+ }
244
+
235
245
@end
0 commit comments