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

Commit 4e0925b

Browse files
committed
Apply reviews
1 parent d2faa10 commit 4e0925b

File tree

8 files changed

+56
-26
lines changed

8 files changed

+56
-26
lines changed

shell/platform/darwin/common/BUILD.gn

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,17 @@ source_set("framework_shared") {
3636
sources = [
3737
"framework/Source/FlutterChannels.mm",
3838
"framework/Source/FlutterCodecs.mm",
39-
"framework/Source/FlutterDartProjectHelper.mm",
39+
"framework/Source/FlutterNSBundleUtils.h",
40+
"framework/Source/FlutterNSBundleUtils.mm",
4041
"framework/Source/FlutterStandardCodec.mm",
4142
"framework/Source/FlutterStandardCodecHelper.cc",
4243
"framework/Source/FlutterStandardCodec_Internal.h",
4344
]
4445

4546
public = framework_shared_headers
4647

48+
public += [ "framework/Source/FlutterNSBundleUtils.h" ]
49+
4750
defines = [ "FLUTTER_FRAMEWORK" ]
4851

4952
public_configs = [

shell/platform/darwin/common/framework/Headers/FlutterDartProject.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ NS_ASSUME_NONNULL_BEGIN
1515
/**
1616
* A set of Flutter and Dart assets used by a `FlutterEngine` to initialize execution.
1717
*
18-
* TODO(stuartmorgan): Align API with FlutterDartProject, and combine.
1918
*/
2019
FLUTTER_DARWIN_EXPORT
2120
@interface FlutterDartProject : NSObject
@@ -40,7 +39,7 @@ FLUTTER_DARWIN_EXPORT
4039
* Returns the default identifier for the bundle where we expect to find the Flutter Dart
4140
* application.
4241
*/
43-
+ (NSString*)defaultBundleIdentifier API_UNAVAILABLE(macos);
42+
+ (NSString*)defaultBundleIdentifier;
4443

4544
/**
4645
* An NSArray of NSStrings to be passed as command line arguments to the Dart entrypoint.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2013 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
#ifndef SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
6+
#define SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_
7+
8+
#import <Foundation/Foundation.h>
9+
10+
NS_ASSUME_NONNULL_BEGIN
11+
12+
// Finds a bundle with the named `bundleID` within `searchURL`.
13+
//
14+
// Returns `nil` if the bundle cannot be found or if errors are encountered.
15+
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL);
16+
17+
// Finds a bundle with the named `bundleID`.
18+
//
19+
// `+[NSBundle bundleWithIdentifier:]` is slow, and can take in the order of
20+
// tens of milliseconds in a minimal flutter app, and closer to 100 milliseconds
21+
// in a medium sized Flutter app on an iPhone 13. It is likely that the slowness
22+
// comes from having to traverse and load all bundles known to the process.
23+
// Using `+[NSBundle allframeworks]` and filtering also suffers from the same
24+
// problem.
25+
//
26+
// This implementation is an optimization to first limit the search space to
27+
// `+[NSBundle privateFrameworksURL]` of the main bundle, which is usually where
28+
// frameworks used by this file are placed. If the desired bundle cannot be
29+
// found here, the implementation falls back to
30+
// `+[NSBundle bundleWithIdentifier:]`.
31+
NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID);
32+
33+
NS_ASSUME_NONNULL_END
34+
35+
#endif // SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_

shell/platform/darwin/common/framework/Source/FlutterDartProjectHelper.mm renamed to shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
#include <Foundation/Foundation.h>
66

7-
// Finds a bundle with the named `bundleID` within `searchURL`.
8-
//
9-
// Returns `nil` if the bundle cannot be found or if errors are encountered.
107
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL) {
118
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager
129
enumeratorAtURL:searchURL
@@ -25,20 +22,6 @@
2522
return nil;
2623
}
2724

28-
// Finds a bundle with the named `bundleID`.
29-
//
30-
// `+[NSBundle bundleWithIdentifier:]` is slow, and can take in the order of
31-
// tens of milliseconds in a minimal flutter app, and closer to 100 milliseconds
32-
// in a medium sized Flutter app on an iPhone 13. It is likely that the slowness
33-
// comes from having to traverse and load all bundles known to the process.
34-
// Using `+[NSBundle allframeworks]` and filtering also suffers from the same
35-
// problem.
36-
//
37-
// This implementation is an optimization to first limit the search space to
38-
// `+[NSBundle privateFrameworksURL]` of the main bundle, which is usually where
39-
// frameworks used by this file are placed. If the desired bundle cannot be
40-
// found here, the implementation falls back to
41-
// `+[NSBundle bundleWithIdentifier:]`.
4225
NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID) {
4326
NSBundle* bundle = FLTFrameworkBundleInternal(bundleID, NSBundle.mainBundle.privateFrameworksURL);
4427
if (bundle != nil) {

shell/platform/darwin/ios/framework/Source/FlutterDartProject_Internal.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99
#include "flutter/runtime/platform_data.h"
1010
#include "flutter/shell/common/engine.h"
1111
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterDartProject.h"
12+
#import "flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h"
1213

1314
NS_ASSUME_NONNULL_BEGIN
1415

15-
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL);
16-
NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID);
17-
1816
flutter::Settings FLTDefaultSettingsForBundle(NSBundle* _Nullable bundle = nil,
1917
NSProcessInfo* _Nullable processInfoOrNil = nil);
2018

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,8 @@ + (NSString*)lookupKeyForAsset:(NSString*)asset
124124
fromBundle:bundle];
125125
}
126126

127+
+ (NSString*)defaultBundleIdentifier {
128+
return kAppBundleIdentifier;
129+
}
130+
127131
@end

shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
#define SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_SOURCE_FLUTTERDARTPROJECT_INTERNAL_H_
77

88
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterDartProject.h"
9+
#import "flutter/shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h"
910

1011
#include <string>
1112
#include <vector>
1213

13-
NSBundle* _Nullable FLTFrameworkBundleWithIdentifier(NSString* _Nonnull bundleID);
14-
1514
/**
1615
* Provides access to data needed to construct a FlutterProjectArgs for the project.
1716
*/

shell/platform/darwin/macos/framework/Source/FlutterViewControllerTest.mm

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ - (bool)testModifierKeysAreSynthesizedOnMouseMove;
6767
- (bool)testViewWillAppearCalledMultipleTimes;
6868
- (bool)testFlutterViewIsConfigured;
6969
- (bool)testLookupKeyAssets;
70+
- (bool)testLookupKeyAssetsWithPackage;
7071

7172
+ (void)respondFalseForSendEvent:(const FlutterKeyEvent&)event
7273
callback:(nullable FlutterKeyEventCallback)callback
@@ -241,6 +242,10 @@ id MockGestureEvent(NSEventType type, NSEventPhase phase, double magnification,
241242
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssets]);
242243
}
243244

245+
TEST(FlutterViewControllerTest, testLookupKeyAssetsWithPackage) {
246+
ASSERT_TRUE([[FlutterViewControllerTestObjC alloc] testLookupKeyAssetsWithPackage]);
247+
}
248+
244249
} // namespace flutter::testing
245250

246251
#pragma mark - FlutterViewControllerTestObjC
@@ -842,9 +847,13 @@ - (bool)testLookupKeyAssets {
842847
NSString* key = [viewController lookupKeyForAsset:@"test.png"];
843848
EXPECT_TRUE(
844849
[key isEqualToString:@"Contents/Frameworks/App.framework/Resources/flutter_assets/test.png"]);
850+
return true;
851+
}
852+
853+
- (bool)testLookupKeyAssetsWithPackage {
854+
FlutterViewController* viewController = [[FlutterViewController alloc] initWithProject:nil];
845855

846856
NSString* packageKey = [viewController lookupKeyForAsset:@"test.png" fromPackage:@"test"];
847-
NSLog(@"%@", packageKey);
848857
EXPECT_TRUE([packageKey
849858
isEqualToString:
850859
@"Contents/Frameworks/App.framework/Resources/flutter_assets/packages/test/test.png"]);

0 commit comments

Comments
 (0)