forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[macOS] Add lookupKeyForAsset to FlutterPluginRegistrar (flutter#37421)
Fixes flutter/flutter#47681 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
- Loading branch information
Showing
18 changed files
with
253 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ |
32 changes: 32 additions & 0 deletions
32
shell/platform/darwin/common/framework/Source/FlutterNSBundleUtils.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 0 additions & 44 deletions
44
shell/platform/darwin/macos/framework/Headers/FlutterDartProject.h
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.