Skip to content

Commit

Permalink
Extract common iOS asset path lookup code (flutter#4594)
Browse files Browse the repository at this point in the history
Consolidates the asset path lookup logic from FlutterDartProject and FlutterMain().
  • Loading branch information
cbracken authored Jan 26, 2018
1 parent 6921873 commit f937d93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ - (instancetype)initFromDefaultSourceForConfiguration {
if (flutterAssetsURL == nil) {
// If the URL was not specified on the command line, look inside the
// FlutterApplication bundle.
NSString* flutterAssetsPath = [self pathForFlutterAssetsFromBundle:bundle];
NSString* flutterAssetsPath = [FlutterDartProject pathForFlutterAssetsFromBundle:bundle];
if (flutterAssetsPath != nil) {
flutterAssetsURL = [NSURL fileURLWithPath:flutterAssetsPath isDirectory:NO];
}
Expand Down Expand Up @@ -154,7 +154,9 @@ - (void)checkReadiness {
}
}

- (NSString*)pathForFlutterAssetsFromBundle:(NSBundle*)bundle {
#pragma mark - Assets-related utilities

+ (NSString*)pathForFlutterAssetsFromBundle:(NSBundle*)bundle {
NSString* flutterAssetsName = [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"];
if (flutterAssetsName == nil) {
// Default to "flutter_assets"
Expand Down Expand Up @@ -269,7 +271,7 @@ - (void)runFromPrecompiledSourceInEngine:(shell::Engine*)engine
return;
}

NSString* path = [self pathForFlutterAssetsFromBundle:_precompiledDartBundle];
NSString* path = [FlutterDartProject pathForFlutterAssetsFromBundle:_precompiledDartBundle];
if (path.length == 0) {
NSString* message = [NSString stringWithFormat:
@"Could not find the 'flutter_assets' dir in "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ typedef void (^LaunchResult)(BOOL success, NSString* message);
embedderVMType:(VMType)type
result:(LaunchResult)result;

+ (NSString*)pathForFlutterAssetsFromBundle:(NSBundle*)bundle;

@end

#endif // SHELL_PLATFORM_IOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_
10 changes: 3 additions & 7 deletions shell/platform/darwin/ios/framework/Source/flutter_main_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
// found in the LICENSE file.

#include "flutter/shell/platform/darwin/ios/framework/Source/flutter_main_ios.h"

#include "flutter/shell/platform/darwin/common/platform_mac.h"
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
#include "flutter/shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h"

namespace shell {

Expand All @@ -14,13 +16,7 @@ void FlutterMain() {
NSString* libraryName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FLTLibraryPath"];

NSBundle* mainBundle = [NSBundle mainBundle];

NSString* flutterAssetsName = [mainBundle objectForInfoDictionaryKey:@"FLTAssetsPath"];
if (flutterAssetsName == nil) {
// Default to "flutter_assets"
flutterAssetsName = @"flutter_assets";
}
NSString* flutterAssetsPath = [mainBundle pathForResource:flutterAssetsName ofType:nil];
NSString* flutterAssetsPath = [FlutterDartProject pathForFlutterAssetsFromBundle:mainBundle];

shell::PlatformMacMain(icuDataPath.UTF8String, libraryName != nil ? libraryName.UTF8String : "",
flutterAssetsPath.UTF8String);
Expand Down

0 comments on commit f937d93

Please sign in to comment.