Skip to content

Commit 523a9a9

Browse files
authored
Add FLEPluginRegistry for macOS (flutter#8611)
Creates a minimal FLEPluginRegistry protocol, which is a subset of the FlutterPluginRegistry. This is a small step toward eventually merging the APIs, but allows changing the example project structure to better reflect what a future template will look like.
1 parent dd9dcaf commit 523a9a9

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
#import "FlutterMacros.h"
1717
#endif
1818

19+
// TODO: Merge this file and FLEPlugin.h with FlutterPlugin.h, sharing all but
20+
// the platform-specific methods.
21+
1922
/**
2023
* The protocol for an object managing registration for a plugin. It provides access to application
2124
* context, as as allowing registering for callbacks for handling various conditions.
@@ -46,3 +49,30 @@ FLUTTER_EXPORT
4649
channel:(nonnull FlutterMethodChannel*)channel;
4750

4851
@end
52+
53+
/**
54+
* A registry of Flutter macOS plugins.
55+
*
56+
* Plugins are identified by unique string keys, typically the name of the
57+
* plugin's main class.
58+
*
59+
* Plugins typically need contextual information and the ability to register
60+
* callbacks for various application events. To keep the API of the registry
61+
* focused, these facilities are not provided directly by the registry, but by
62+
* a `FlutterPluginRegistrar`, created by the registry in exchange for the unique
63+
* key of the plugin.
64+
*
65+
* There is no implied connection between the registry and the registrar.
66+
* Specifically, callbacks registered by the plugin via the registrar may be
67+
* relayed directly to the underlying iOS application objects.
68+
*/
69+
@protocol FLEPluginRegistry <NSObject>
70+
71+
/**
72+
* Returns a registrar for registering a plugin.
73+
*
74+
* @param pluginKey The unique key identifying the plugin.
75+
*/
76+
- (nonnull id<FLEPluginRegistrar>)registrarForPlugin:(nonnull NSString*)pluginKey;
77+
78+
@end

shell/platform/darwin/macos/framework/Headers/FLEViewController.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) {
3535
* Flutter engine in non-interactive mode, or with a drawable Flutter canvas.
3636
*/
3737
FLUTTER_EXPORT
38-
@interface FLEViewController
39-
: NSViewController <FlutterBinaryMessenger, FLEPluginRegistrar, FLEReshapeListener>
38+
@interface FLEViewController : NSViewController <FlutterBinaryMessenger,
39+
FLEPluginRegistrar,
40+
FLEPluginRegistry,
41+
FLEReshapeListener>
4042

4143
/**
4244
* The view this controller manages when launched in interactive mode (headless set to false). Must
@@ -73,9 +75,4 @@ FLUTTER_EXPORT
7375
- (BOOL)launchHeadlessEngineWithAssetsPath:(nonnull NSURL*)assets
7476
commandLineArguments:(nullable NSArray<NSString*>*)arguments;
7577

76-
/**
77-
* Returns the FLEPluginRegistrar that should be used to register the plugin with the given name.
78-
*/
79-
- (nonnull id<FLEPluginRegistrar>)registrarForPlugin:(nonnull NSString*)pluginName;
80-
8178
@end

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,13 +251,6 @@ - (BOOL)launchHeadlessEngineWithAssetsPath:(NSURL*)assets
251251
commandLineArguments:arguments];
252252
}
253253

254-
- (id<FLEPluginRegistrar>)registrarForPlugin:(NSString*)pluginName {
255-
// Currently, the view controller acts as the registrar for all plugins, so the
256-
// name is ignored. It is part of the API to reduce churn in the future when
257-
// aligning more closely with the Flutter registrar system.
258-
return self;
259-
}
260-
261254
#pragma mark - Framework-internal methods
262255

263256
- (void)addKeyResponder:(NSResponder*)responder {
@@ -529,6 +522,14 @@ - (void)addMethodCallDelegate:(nonnull id<FLEPlugin>)delegate
529522
}];
530523
}
531524

525+
#pragma mark - FLEPluginRegistry
526+
527+
- (id<FLEPluginRegistrar>)registrarForPlugin:(NSString*)pluginName {
528+
// Currently, the view controller acts as the registrar for all plugins, so the
529+
// name is ignored.
530+
return self;
531+
}
532+
532533
#pragma mark - NSResponder
533534

534535
- (BOOL)acceptsFirstResponder {

0 commit comments

Comments
 (0)