| Flutter macOS Embedder |

FlutterPluginRegistrarMacOS.h
Go to the documentation of this file.
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 FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_HEADERS_FLUTTERPLUGINREGISTRARMACOS_H_
6 #define FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_HEADERS_FLUTTERPLUGINREGISTRARMACOS_H_
7
8 #import <Cocoa/Cocoa.h>
9
10 #import "FlutterBinaryMessenger.h"
11 #import "FlutterChannels.h"
12 #import "FlutterMacros.h"
13 #import "FlutterPlatformViews.h"
14 #import "FlutterPluginMacOS.h"
15 #import "FlutterTexture.h"
16
17 // TODO(stuartmorgan): Merge this file and FlutterPluginMacOS.h with the iOS FlutterPlugin.h,
18 // sharing all but the platform-specific methods.
19
20 /**
21 * The protocol for an object managing registration for a plugin. It provides access to application
22 * context, as allowing registering for callbacks for handling various conditions.
23 *
24 * Currently the macOS PluginRegistrar has very limited functionality, but is expected to expand
25 * over time to more closely match the functionality of FlutterPluginRegistrar.
26 */
27 FLUTTER_DARWIN_EXPORT
28 @protocol FlutterPluginRegistrar <NSObject>
29
30 /**
31 * The binary messenger used for creating channels to communicate with the Flutter engine.
32 */
33 @property(nonnull, readonly) id<FlutterBinaryMessenger> messenger;
34
35 /**
36 * Returns a `FlutterTextureRegistry` for registering textures
37 * provided by the plugin.
38 */
39 @property(nonnull, readonly) id<FlutterTextureRegistry> textures;
40
41 /**
42 * The view displaying Flutter content.
43 *
44 * This property is provided for backwards compatibility for apps
45 * that assume a single view. This will eventually be replaced by
46 * a multi-view API variant.
47 *
48 * This method may return |nil|, for instance in a headless environment.
49 */
50 @property(nullable, readonly) NSView* view;
51
52 /**
53 * The `NSViewController` that hosts |view|.
54 *
55 * The plugin typically should not store a strong reference to this view
56 * controller.
57 *
58 * This property is provided for backwards compatibility for apps that assume
59 * a single view, and will eventually be replaced by the multi-view API variant.
60 *
61 * This property is |nil| when |view| is |nil|.
62 */
63 @property(nullable, readonly) NSViewController* viewController;
64
65 /**
66 * Registers |delegate| to receive handleMethodCall:result: callbacks for the given |channel|.
67 */
68 - (void)addMethodCallDelegate:(nonnull id<FlutterPlugin>)delegate
69 channel:(nonnull FlutterMethodChannel*)channel;
70
71 /**
72 * Registers the plugin as a receiver of `NSApplicationDelegate` calls.
73 *
74 * @param delegate The receiving object, such as the plugin's main class.
75 */
76 - (void)addApplicationDelegate:(nonnull NSObject<FlutterAppLifecycleDelegate>*)delegate;
77
78 /**
79 * Registers a `FlutterPlatformViewFactory` for creation of platform views.
80 *
81 * Plugins expose `NSView` for embedding in Flutter apps by registering a view factory.
82 *
83 * @param factory The view factory that will be registered.
84 * @param factoryId A unique identifier for the factory, the Dart code of the Flutter app can use
85 * this identifier to request creation of a `NSView` by the registered factory.
86 */
87 - (void)registerViewFactory:(nonnull NSObject<FlutterPlatformViewFactory>*)factory
88 withId:(nonnull NSString*)factoryId;
89
90 /**
91 * Publishes a value for external use of the plugin.
92 *
93 * Plugins may publish a single value, such as an instance of the
94 * plugin's main class, for situations where external control or
95 * interaction is needed.
96 *
97 * The published value will be available from the `FlutterPluginRegistry`.
98 * Repeated calls overwrite any previous publication.
99 *
100 * @param value The value to be published.
101 */
102 - (void)publish:(nonnull NSObject*)value;
103
104 /**
105 * Returns the file name for the given asset.
106 * The returned file name can be used to access the asset in the application's main bundle.
107 *
108 * @param asset The name of the asset. The name can be hierarchical.
109 * @return the file name to be used for lookup in the main bundle.
110 */
111 - (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset;
112
113 /**
114 * Returns the file name for the given asset which originates from the specified package.
115 * The returned file name can be used to access the asset in the application's main bundle.
116 *
117 *
118 * @param asset The name of the asset. The name can be hierarchical.
119 * @param package The name of the package from which the asset originates.
120 * @return the file name to be used for lookup in the main bundle.
121 */
122 - (nonnull NSString*)lookupKeyForAsset:(nonnull NSString*)asset
123 fromPackage:(nonnull NSString*)package;
124
125 @end
126
127 /**
128 * A registry of Flutter macOS plugins.
129 *
130 * Plugins are identified by unique string keys, typically the name of the
131 * plugin's main class.
132 *
133 * Plugins typically need contextual information and the ability to register
134 * callbacks for various application events. To keep the API of the registry
135 * focused, these facilities are not provided directly by the registry, but by
136 * a `FlutterPluginRegistrar`, created by the registry in exchange for the unique
137 * key of the plugin.
138 *
139 * There is no implied connection between the registry and the registrar.
140 * Specifically, callbacks registered by the plugin via the registrar may be
141 * relayed directly to the underlying iOS application objects.
142 */
143 @protocol FlutterPluginRegistry <NSObject>
144
145 /**
146 * Returns a registrar for registering a plugin.
147 *
148 * @param pluginKey The unique key identifying the plugin.
149 */
150 - (nonnull id<FlutterPluginRegistrar>)registrarForPlugin:(nonnull NSString*)pluginKey;
151
152 /**
153 * Returns a value published by the specified plugin.
154 *
155 * @param pluginKey The unique key identifying the plugin.
156 * @return An object published by the plugin, if any. Will be `NSNull` if
157 * nothing has been published. Will be `nil` if the plugin has not been
158 * registered.
159 */
160 - (nullable NSObject*)valuePublishedByPlugin:(nonnull NSString*)pluginKey;
161
162 @end
163
164 #endif // FLUTTER_SHELL_PLATFORM_DARWIN_MACOS_FRAMEWORK_HEADERS_FLUTTERPLUGINREGISTRARMACOS_H_
FlutterBinaryMessenger.h
FlutterChannels.h
FlutterMacros.h
FLUTTER_DARWIN_EXPORT
#define FLUTTER_DARWIN_EXPORT
Definition: FlutterMacros.h:14
FlutterPlatformViews.h
FlutterPluginMacOS.h
FlutterTexture.h
FlutterMethodChannel
Definition: FlutterChannels.h:221
FlutterAppLifecycleDelegate-p
Definition: FlutterAppLifecycleDelegate.h:21
FlutterPlatformViewFactory-p
Definition: FlutterPlatformViews.h:13
FlutterPlugin-p
Definition: FlutterPluginMacOS.h:29
FlutterPluginRegistrar-p
Definition: FlutterPluginRegistrarMacOS.h:28
FlutterPluginRegistrar-p::viewController
NSViewController * viewController
Definition: FlutterPluginRegistrarMacOS.h:63
FlutterPluginRegistrar-p::messenger
id< FlutterBinaryMessenger > messenger
Definition: FlutterPluginRegistrarMacOS.h:33
FlutterPluginRegistrar-p::textures
id< FlutterTextureRegistry > textures
Definition: FlutterPluginRegistrarMacOS.h:39
FlutterPluginRegistrar-p::view
NSView * view
Definition: FlutterPluginRegistrarMacOS.h:50