@@ -24,15 +24,15 @@ @implementation FLEColorPanelPlugin {
24
24
}
25
25
26
26
+ (void )registerWithRegistrar : (id <FLEPluginRegistrar>)registrar {
27
- FLEMethodChannel* channel = [FLEMethodChannel
28
- methodChannelWithName: @(plugins_color_panel: :kChannelName )
29
- binaryMessenger: registrar.messenger
30
- codec: [FLEJSONMethodCodec sharedInstance ]];
31
- FLEColorPanelPlugin* instance = [[FLEColorPanelPlugin alloc ] initWithChannel: channel];
27
+ FLEMethodChannel * channel =
28
+ [FLEMethodChannel methodChannelWithName: @(plugins_color_panel: :kChannelName )
29
+ binaryMessenger: registrar.messenger
30
+ codec: [FLEJSONMethodCodec sharedInstance ]];
31
+ FLEColorPanelPlugin * instance = [[FLEColorPanelPlugin alloc ] initWithChannel: channel];
32
32
[registrar addMethodCallDelegate: instance channel: channel];
33
33
}
34
34
35
- - (instancetype )initWithChannel : (FLEMethodChannel*)channel {
35
+ - (instancetype )initWithChannel : (FLEMethodChannel *)channel {
36
36
self = [super init ];
37
37
if (self) {
38
38
_channel = channel;
@@ -45,26 +45,29 @@ - (instancetype)initWithChannel:(FLEMethodChannel*)channel {
45
45
* panel channel.
46
46
*/
47
47
- (void )handleMethodCall : (FLEMethodCall *)call result : (FLEMethodResult)result {
48
- BOOL handled = YES ;
48
+ id methodResult = nil ;
49
49
if ([call.methodName isEqualToString: @(plugins_color_panel: :kShowColorPanelMethod )]) {
50
50
if ([call.arguments isKindOfClass: [NSDictionary class ]]) {
51
51
BOOL showAlpha =
52
52
[[call.arguments valueForKey: @(plugins_color_panel: :kColorPanelShowAlpha )] boolValue ];
53
53
[self showColorPanelWithAlpha: showAlpha];
54
54
} else {
55
- NSLog (@" Malformed call for %@ . Expected an NSDictionary but got %@ " ,
56
- @(plugins_color_panel::kShowColorPanelMethod ),
57
- NSStringFromClass([call.arguments class ]));
58
- handled = NO ;
55
+ NSString *errorString =
56
+ [NSString stringWithFormat: @" Malformed call for %@ . Expected an NSDictionary but got %@ " ,
57
+ @(plugins_color_panel: :kShowColorPanelMethod ),
58
+ NSStringFromClass ([call.arguments class ])];
59
+ methodResult = [[FLEMethodError alloc ] initWithCode: @" Bad arguments"
60
+ message: errorString
61
+ details: nil ];
59
62
}
60
63
} else if ([call.methodName isEqualToString: @(plugins_color_panel: :kHideColorPanelMethod )]) {
61
64
[self hideColorPanel ];
62
65
} else {
63
- handled = NO ;
66
+ methodResult = FLEMethodNotImplemented ;
64
67
}
65
- // Send an immediate empty success message for handled messages, since the actual color data
66
- // will be provided in follow-up messages.
67
- result (handled ? nil : FLEMethodNotImplemented );
68
+ // If no errors are generated, send an immediate empty success message for handled messages, since
69
+ // the actual color data will be provided in follow-up messages.
70
+ result (methodResult );
68
71
}
69
72
70
73
/* *
@@ -114,7 +117,7 @@ - (void)selectedColorDidChange {
114
117
NSColor *color = [NSColorPanel sharedColorPanel ].color ;
115
118
NSDictionary *colorDictionary = [self dictionaryWithColor: color];
116
119
[_channel invokeMethod: @(plugins_color_panel: :kColorSelectedCallbackMethod )
117
- arguments: colorDictionary];
120
+ arguments: colorDictionary];
118
121
}
119
122
120
123
/* *
@@ -138,8 +141,7 @@ - (NSDictionary *)dictionaryWithColor:(NSColor *)color {
138
141
139
142
- (void )windowWillClose: (NSNotification *)notification {
140
143
[self removeColorPanelConnections ];
141
- [_channel invokeMethod: @(plugins_color_panel: :kClosedCallbackMethod )
142
- arguments: nil ];
144
+ [_channel invokeMethod: @(plugins_color_panel: :kClosedCallbackMethod ) arguments: nil ];
143
145
}
144
146
145
147
@end
0 commit comments