From 523a9a9adde96d22c801eac59f9f6db3d2a79a30 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Wed, 17 Apr 2019 10:53:59 -0700 Subject: [PATCH] Add FLEPluginRegistry for macOS (#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. --- .../framework/Headers/FLEPluginRegistrar.h | 30 +++++++++++++++++++ .../framework/Headers/FLEViewController.h | 11 +++---- .../framework/Source/FLEViewController.mm | 15 +++++----- 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.h b/shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.h index b9f7ac99b2..b15a659136 100644 --- a/shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.h +++ b/shell/platform/darwin/macos/framework/Headers/FLEPluginRegistrar.h @@ -16,6 +16,9 @@ #import "FlutterMacros.h" #endif +// TODO: Merge this file and FLEPlugin.h with FlutterPlugin.h, sharing all but +// the platform-specific methods. + /** * The protocol for an object managing registration for a plugin. It provides access to application * context, as as allowing registering for callbacks for handling various conditions. @@ -46,3 +49,30 @@ FLUTTER_EXPORT channel:(nonnull FlutterMethodChannel*)channel; @end + +/** + * A registry of Flutter macOS plugins. + * + * Plugins are identified by unique string keys, typically the name of the + * plugin's main class. + * + * Plugins typically need contextual information and the ability to register + * callbacks for various application events. To keep the API of the registry + * focused, these facilities are not provided directly by the registry, but by + * a `FlutterPluginRegistrar`, created by the registry in exchange for the unique + * key of the plugin. + * + * There is no implied connection between the registry and the registrar. + * Specifically, callbacks registered by the plugin via the registrar may be + * relayed directly to the underlying iOS application objects. + */ +@protocol FLEPluginRegistry + +/** + * Returns a registrar for registering a plugin. + * + * @param pluginKey The unique key identifying the plugin. + */ +- (nonnull id)registrarForPlugin:(nonnull NSString*)pluginKey; + +@end diff --git a/shell/platform/darwin/macos/framework/Headers/FLEViewController.h b/shell/platform/darwin/macos/framework/Headers/FLEViewController.h index e831934cd1..c66cba2130 100644 --- a/shell/platform/darwin/macos/framework/Headers/FLEViewController.h +++ b/shell/platform/darwin/macos/framework/Headers/FLEViewController.h @@ -35,8 +35,10 @@ typedef NS_ENUM(NSInteger, FlutterMouseTrackingMode) { * Flutter engine in non-interactive mode, or with a drawable Flutter canvas. */ FLUTTER_EXPORT -@interface FLEViewController - : NSViewController +@interface FLEViewController : NSViewController /** * The view this controller manages when launched in interactive mode (headless set to false). Must @@ -73,9 +75,4 @@ FLUTTER_EXPORT - (BOOL)launchHeadlessEngineWithAssetsPath:(nonnull NSURL*)assets commandLineArguments:(nullable NSArray*)arguments; -/** - * Returns the FLEPluginRegistrar that should be used to register the plugin with the given name. - */ -- (nonnull id)registrarForPlugin:(nonnull NSString*)pluginName; - @end diff --git a/shell/platform/darwin/macos/framework/Source/FLEViewController.mm b/shell/platform/darwin/macos/framework/Source/FLEViewController.mm index b0f732e310..d094170375 100644 --- a/shell/platform/darwin/macos/framework/Source/FLEViewController.mm +++ b/shell/platform/darwin/macos/framework/Source/FLEViewController.mm @@ -251,13 +251,6 @@ static void CommonInit(FLEViewController* controller) { commandLineArguments:arguments]; } -- (id)registrarForPlugin:(NSString*)pluginName { - // Currently, the view controller acts as the registrar for all plugins, so the - // name is ignored. It is part of the API to reduce churn in the future when - // aligning more closely with the Flutter registrar system. - return self; -} - #pragma mark - Framework-internal methods - (void)addKeyResponder:(NSResponder*)responder { @@ -529,6 +522,14 @@ static void CommonInit(FLEViewController* controller) { }]; } +#pragma mark - FLEPluginRegistry + +- (id)registrarForPlugin:(NSString*)pluginName { + // Currently, the view controller acts as the registrar for all plugins, so the + // name is ignored. + return self; +} + #pragma mark - NSResponder - (BOOL)acceptsFirstResponder { -- GitLab