Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
draft

draft

darft

fix

format

format

format

format

format

froma

format
  • Loading branch information
Chris Yang committed Sep 25, 2023
1 parent d64abdb commit dcdba2c
Show file tree
Hide file tree
Showing 33 changed files with 1,155 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ NSString* FLTAssetPath(NSBundle* bundle);
// If the key is not set, `flutter_assets` is used as the raw path value.
//
// If no valid asset is found under the raw path, returns nil.
NSString* FLTAssetsPathFromBundle(NSBundle* bundle);
NSURL* FLTAssetsURLFromBundle(NSBundle* bundle);

NS_ASSUME_NONNULL_END

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,20 @@
return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath;
}

NSString* FLTAssetsPathFromBundle(NSBundle* bundle) {
NSURL* FLTAssetsURLFromBundle(NSBundle* bundle) {
NSString* flutterAssetsPath = FLTAssetPath(bundle);
// Use the raw path solution so that asset path can be returned from unloaded bundles.
// See https://github.com/flutter/engine/pull/46073
NSString* assetsPath = [bundle pathForResource:flutterAssetsPath ofType:@""];
NSURL* assets = [bundle URLForResource:flutterAssetsPath withExtension:nil];
if (!assets) {
// When bundle is not loaded, using the sub folder path returns a non-nil result.
// See https://github.com/flutter/engine/pull/46073
assets = [bundle URLForResource:@"flutter_assets" withExtension:nil];
}

if (assetsPath.length == 0) {
assetsPath = [[NSBundle mainBundle] pathForResource:flutterAssetsPath ofType:@""];
if (!assets) {
assets = [[NSBundle mainBundle] URLForResource:flutterAssetsPath withExtension:nil];
}
if (!assets) {
assets = [[NSBundle mainBundle] URLForResource:@"flutter_assets" withExtension:nil];
}
return assetsPath;
return assets;
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,19 @@ static BOOL DoesHardwareSupportWideGamut() {

// Checks to see if the flutter assets directory is already present.
if (settings.assets_path.empty()) {
NSString* assetsPath = FLTAssetsPathFromBundle(bundle);
NSURL* assetsURL = FLTAssetsURLFromBundle(bundle);

if (assetsPath.length == 0) {
if (!assetsURL) {
NSLog(@"Failed to find assets path for \"%@\"", bundle);
} else {
settings.assets_path = assetsPath.UTF8String;
settings.assets_path = assetsURL.path.UTF8String;

// Check if there is an application kernel snapshot in the assets directory we could
// potentially use. Looking for the snapshot makes sense only if we have a VM that can use
// it.
if (!flutter::DartVM::IsRunningPrecompiledCode()) {
NSURL* applicationKernelSnapshotURL =
[NSURL URLWithString:@(kApplicationKernelSnapshotFileName)
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
[assetsURL URLByAppendingPathComponent:@(kApplicationKernelSnapshotFileName)];
NSError* error;
if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&error]) {
settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,22 +92,28 @@ - (void)testFLTAssetsURLFromBundle {
// Found asset path in info.plist
id mockBundle = OCMClassMock([NSBundle class]);
OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets");
NSString* resultAssetsPath = @"path/to/foo/assets";
OCMStub([mockBundle pathForResource:@"foo/assets" ofType:@""]).andReturn(resultAssetsPath);
NSString* path = FLTAssetsPathFromBundle(mockBundle);
XCTAssertEqualObjects(path, @"path/to/foo/assets");
NSURL* mockAssetsURL = OCMClassMock([NSURL class]);
OCMStub([mockBundle URLForResource:@"foo/assets" withExtension:nil]).andReturn(mockAssetsURL);
OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO);
OCMStub([mockAssetsURL path]).andReturn(@"foo/assets");
NSURL* url = FLTAssetsURLFromBundle(mockBundle);
XCTAssertEqualObjects(url.path, @"foo/assets");
}
{
// No asset path in info.plist, defaults to main bundle
id mockBundle = OCMClassMock([NSBundle class]);
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
NSString* resultAssetsPath = @"path/to/foo/assets";
OCMStub([mockBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
NSURL* mockAssetsURL = OCMClassMock([NSURL class]);
OCMStub([mockBundle URLForResource:@"Frameworks/App.framework/flutter_assets"
withExtension:nil])
.andReturn(nil);
OCMStub([mockMainBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
.andReturn(resultAssetsPath);
NSString* path = FLTAssetsPathFromBundle(mockBundle);
XCTAssertEqualObjects(path, @"path/to/foo/assets");
OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO);
OCMStub([mockAssetsURL path]).andReturn(@"path/to/foo/assets");
OCMStub([mockMainBundle URLForResource:@"Frameworks/App.framework/flutter_assets"
withExtension:nil])
.andReturn(mockAssetsURL);
NSURL* url = FLTAssetsURLFromBundle(mockBundle);
XCTAssertEqualObjects(url.path, @"path/to/foo/assets");
}
}

Expand Down
Loading

0 comments on commit dcdba2c

Please sign in to comment.