Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit dcdba2c

Browse files
author
Chris Yang
committed
draft
draft draft darft fix format format format format format froma format
1 parent d64abdb commit dcdba2c

File tree

33 files changed

+1155
-24
lines changed

33 files changed

+1155
-24
lines changed

shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ NSString* FLTAssetPath(NSBundle* bundle);
4848
// If the key is not set, `flutter_assets` is used as the raw path value.
4949
//
5050
// If no valid asset is found under the raw path, returns nil.
51-
NSString* FLTAssetsPathFromBundle(NSBundle* bundle);
51+
NSURL* FLTAssetsURLFromBundle(NSBundle* bundle);
5252

5353
NS_ASSUME_NONNULL_END
5454

shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@
5757
return [bundle objectForInfoDictionaryKey:@"FLTAssetsPath"] ?: kDefaultAssetPath;
5858
}
5959

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

66-
if (assetsPath.length == 0) {
67-
assetsPath = [[NSBundle mainBundle] pathForResource:flutterAssetsPath ofType:@""];
69+
if (!assets) {
70+
assets = [[NSBundle mainBundle] URLForResource:flutterAssetsPath withExtension:nil];
71+
}
72+
if (!assets) {
73+
assets = [[NSBundle mainBundle] URLForResource:@"flutter_assets" withExtension:nil];
6874
}
69-
return assetsPath;
75+
return assets;
7076
}

shell/platform/darwin/ios/framework/Source/FlutterDartProject.mm

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,20 +139,19 @@ static BOOL DoesHardwareSupportWideGamut() {
139139

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

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

149149
// Check if there is an application kernel snapshot in the assets directory we could
150150
// potentially use. Looking for the snapshot makes sense only if we have a VM that can use
151151
// it.
152152
if (!flutter::DartVM::IsRunningPrecompiledCode()) {
153153
NSURL* applicationKernelSnapshotURL =
154-
[NSURL URLWithString:@(kApplicationKernelSnapshotFileName)
155-
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
154+
[assetsURL URLByAppendingPathComponent:@(kApplicationKernelSnapshotFileName)];
156155
NSError* error;
157156
if ([applicationKernelSnapshotURL checkResourceIsReachableAndReturnError:&error]) {
158157
settings.application_kernel_asset = applicationKernelSnapshotURL.path.UTF8String;

shell/platform/darwin/ios/framework/Source/FlutterDartProjectTest.mm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,22 +92,28 @@ - (void)testFLTAssetsURLFromBundle {
9292
// Found asset path in info.plist
9393
id mockBundle = OCMClassMock([NSBundle class]);
9494
OCMStub([mockBundle objectForInfoDictionaryKey:@"FLTAssetsPath"]).andReturn(@"foo/assets");
95-
NSString* resultAssetsPath = @"path/to/foo/assets";
96-
OCMStub([mockBundle pathForResource:@"foo/assets" ofType:@""]).andReturn(resultAssetsPath);
97-
NSString* path = FLTAssetsPathFromBundle(mockBundle);
98-
XCTAssertEqualObjects(path, @"path/to/foo/assets");
95+
NSURL* mockAssetsURL = OCMClassMock([NSURL class]);
96+
OCMStub([mockBundle URLForResource:@"foo/assets" withExtension:nil]).andReturn(mockAssetsURL);
97+
OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO);
98+
OCMStub([mockAssetsURL path]).andReturn(@"foo/assets");
99+
NSURL* url = FLTAssetsURLFromBundle(mockBundle);
100+
XCTAssertEqualObjects(url.path, @"foo/assets");
99101
}
100102
{
101103
// No asset path in info.plist, defaults to main bundle
102104
id mockBundle = OCMClassMock([NSBundle class]);
103105
id mockMainBundle = OCMPartialMock([NSBundle mainBundle]);
104-
NSString* resultAssetsPath = @"path/to/foo/assets";
105-
OCMStub([mockBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
106+
NSURL* mockAssetsURL = OCMClassMock([NSURL class]);
107+
OCMStub([mockBundle URLForResource:@"Frameworks/App.framework/flutter_assets"
108+
withExtension:nil])
106109
.andReturn(nil);
107-
OCMStub([mockMainBundle pathForResource:@"Frameworks/App.framework/flutter_assets" ofType:@""])
108-
.andReturn(resultAssetsPath);
109-
NSString* path = FLTAssetsPathFromBundle(mockBundle);
110-
XCTAssertEqualObjects(path, @"path/to/foo/assets");
110+
OCMStub([mockAssetsURL checkResourceIsReachableAndReturnError:NULL]).andReturn(NO);
111+
OCMStub([mockAssetsURL path]).andReturn(@"path/to/foo/assets");
112+
OCMStub([mockMainBundle URLForResource:@"Frameworks/App.framework/flutter_assets"
113+
withExtension:nil])
114+
.andReturn(mockAssetsURL);
115+
NSURL* url = FLTAssetsURLFromBundle(mockBundle);
116+
XCTAssertEqualObjects(url.path, @"path/to/foo/assets");
111117
}
112118
}
113119

0 commit comments

Comments
 (0)