-
Notifications
You must be signed in to change notification settings - Fork 6k
[macOS] Add lookupKeyForAsset to FlutterPluginRegistrar #37421
Changes from all commits
2d43d42
7541807
d1b8d0d
b037739
de48136
971ac3a
5973371
2423e1e
e0c36bf
a2bdad8
a9249a7
eddd1b1
c270f94
58365ef
48eb2fa
335ad66
3d06ecf
8e83199
d2faa10
4e0925b
d253d3e
3b3e6aa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,32 +6,57 @@ | |
#define FLUTTER_FLUTTERDARTPROJECT_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <TargetConditionals.h> | ||
|
||
#import "FlutterMacros.h" | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @stuartmorgan and I may disagree on this, but I prefer I don't want to start moving the other way in the iOS embedder since this is now in Interestingly it looks like the Cocoa headers no longer use this macro, and instead uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I prefer to use explicit annotations, to match the way Apple recommends in their docs: https://developer.apple.com/documentation/swift/designating-nullability-in-objective-c-apis#Annotate-Nullability-of-Individual-Declarations 😉 (More seriously, I'm not aware of any actual recommendation by Apple to use one vs the other; on that page they document both and don't seem to indicated a preferred version. They do say you can "simplify the process" by using the macros, but the core argument from the anti-macro camp, of which I am a member, is that simplifying the process at the expense of the correctness of the result of the process is not a good tradeoff, and the problem is right in the macro name: "assume".)
We are agreed on this; every other header in the directory uses the macros currently, so this header should as well; inconsistency actually makes the problem of the macros worse than using the macros everywhere, so if there were to be a change to the pattern for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
||
/** | ||
* A set of Flutter and Dart assets used by a `FlutterEngine` to initialize execution. | ||
* | ||
*/ | ||
FLUTTER_DARWIN_EXPORT | ||
@interface FlutterDartProject : NSObject | ||
|
||
/** | ||
* Initializes a Flutter Dart project from a bundle. | ||
* | ||
* The bundle must either contain a flutter_assets resource directory, or set the Info.plist key | ||
* FLTAssetsPath to override that name (if you are doing a custom build using a different name). | ||
* | ||
* @param bundle The bundle containing the Flutter assets directory. If nil, the App framework | ||
* created by Flutter will be used. | ||
*/ | ||
- (instancetype)initWithPrecompiledDartBundle:(nullable NSBundle*)bundle NS_DESIGNATED_INITIALIZER; | ||
|
||
/** | ||
* Unavailable - use `init` instead. | ||
*/ | ||
- (instancetype)initFromDefaultSourceForConfiguration FLUTTER_UNAVAILABLE("Use -init instead."); | ||
- (instancetype)initFromDefaultSourceForConfiguration API_UNAVAILABLE(macos) | ||
FLUTTER_UNAVAILABLE("Use -init instead."); | ||
|
||
/** | ||
* Returns the default identifier for the bundle where we expect to find the Flutter Dart | ||
* application. | ||
*/ | ||
+ (NSString*)defaultBundleIdentifier; | ||
|
||
/** | ||
* An NSArray of NSStrings to be passed as command line arguments to the Dart entrypoint. | ||
* | ||
* If this is not explicitly set, this will default to the contents of | ||
* [NSProcessInfo arguments], without the binary name. | ||
* | ||
* Set this to nil to pass no arguments to the Dart entrypoint. | ||
*/ | ||
@property(nonatomic, nullable, copy) | ||
NSArray<NSString*>* dartEntrypointArguments API_UNAVAILABLE(ios); | ||
|
||
/** | ||
* Returns the file name for the given asset. If the bundle with the identifier | ||
* "io.flutter.flutter.app" exists, it will try use that bundle; otherwise, it | ||
* will use the main bundle. To specify a different bundle, use | ||
* `-lookupKeyForAsset:asset:fromBundle`. | ||
* `+lookupKeyForAsset:fromBundle`. | ||
* | ||
* @param asset The name of the asset. The name can be hierarchical. | ||
* @return the file name to be used for lookup in the main bundle. | ||
|
@@ -71,12 +96,6 @@ FLUTTER_DARWIN_EXPORT | |
fromPackage:(NSString*)package | ||
fromBundle:(nullable NSBundle*)bundle; | ||
|
||
/** | ||
* Returns the default identifier for the bundle where we expect to find the Flutter Dart | ||
* application. | ||
*/ | ||
+ (NSString*)defaultBundleIdentifier; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_ | ||
#define SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_ | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
// Finds a bundle with the named `bundleID` within `searchURL`. | ||
// | ||
// Returns `nil` if the bundle cannot be found or if errors are encountered. | ||
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL); | ||
|
||
// Finds a bundle with the named `bundleID`. | ||
// | ||
// `+[NSBundle bundleWithIdentifier:]` is slow, and can take in the order of | ||
// tens of milliseconds in a minimal flutter app, and closer to 100 milliseconds | ||
// in a medium sized Flutter app on an iPhone 13. It is likely that the slowness | ||
// comes from having to traverse and load all bundles known to the process. | ||
// Using `+[NSBundle allframeworks]` and filtering also suffers from the same | ||
// problem. | ||
// | ||
// This implementation is an optimization to first limit the search space to | ||
// `+[NSBundle privateFrameworksURL]` of the main bundle, which is usually where | ||
// frameworks used by this file are placed. If the desired bundle cannot be | ||
// found here, the implementation falls back to | ||
// `+[NSBundle bundleWithIdentifier:]`. | ||
NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID); | ||
|
||
NS_ASSUME_NONNULL_END | ||
|
||
#endif // SHELL_PLATFORM_DARWIN_COMMON_FRAMEWORK_SOURCE_FLUTTERNSBUNDLEUTILS_H_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2013 The Flutter Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include <Foundation/Foundation.h> | ||
|
||
NSBundle* FLTFrameworkBundleInternal(NSString* bundleID, NSURL* searchURL) { | ||
NSDirectoryEnumerator<NSURL*>* frameworkEnumerator = [NSFileManager.defaultManager | ||
enumeratorAtURL:searchURL | ||
includingPropertiesForKeys:nil | ||
options:NSDirectoryEnumerationSkipsSubdirectoryDescendants | | ||
NSDirectoryEnumerationSkipsHiddenFiles | ||
// Skip directories where errors are encountered. | ||
errorHandler:nil]; | ||
|
||
for (NSURL* candidate in frameworkEnumerator) { | ||
NSBundle* bundle = [NSBundle bundleWithURL:candidate]; | ||
if ([bundle.bundleIdentifier isEqualToString:bundleID]) { | ||
return bundle; | ||
} | ||
} | ||
return nil; | ||
} | ||
|
||
NSBundle* FLTFrameworkBundleWithIdentifier(NSString* bundleID) { | ||
NSBundle* bundle = FLTFrameworkBundleInternal(bundleID, NSBundle.mainBundle.privateFrameworksURL); | ||
if (bundle != nil) { | ||
return bundle; | ||
} | ||
// Fallback to slow implementation. | ||
return [NSBundle bundleWithIdentifier:bundleID]; | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't cause it to be in the public headers directory of the actual final framework bundle, does it?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just be shared between macos and iOS framework internal.Not affect final public headers.