@@ -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,30 @@ - (instancetype)initWithChannel:(FLEMethodChannel*)channel {
45
45
* panel channel.
46
46
*/
47
47
- (void )handleMethodCall : (FLEMethodCall *)call result : (FLEMethodResult)result {
48
- BOOL handled = YES ;
48
+ BOOL methodImplemented = YES ;
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
+ result ([[FLEMethodError alloc ] initWithCode: @" error"
60
+ message: @" Bad arguments"
61
+ details: errorString]);
62
+ return ;
59
63
}
60
64
} else if ([call.methodName isEqualToString: @(plugins_color_panel: :kHideColorPanelMethod )]) {
61
65
[self hideColorPanel ];
62
66
} else {
63
- handled = NO ;
67
+ methodImplemented = NO ;
64
68
}
65
69
// Send an immediate empty success message for handled messages, since the actual color data
66
70
// will be provided in follow-up messages.
67
- result (handled ? nil : FLEMethodNotImplemented);
71
+ result (methodImplemented ? nil : FLEMethodNotImplemented);
68
72
}
69
73
70
74
/* *
@@ -114,7 +118,7 @@ - (void)selectedColorDidChange {
114
118
NSColor *color = [NSColorPanel sharedColorPanel ].color ;
115
119
NSDictionary *colorDictionary = [self dictionaryWithColor: color];
116
120
[_channel invokeMethod: @(plugins_color_panel: :kColorSelectedCallbackMethod )
117
- arguments: colorDictionary];
121
+ arguments: colorDictionary];
118
122
}
119
123
120
124
/* *
@@ -138,8 +142,7 @@ - (NSDictionary *)dictionaryWithColor:(NSColor *)color {
138
142
139
143
- (void )windowWillClose: (NSNotification *)notification {
140
144
[self removeColorPanelConnections ];
141
- [_channel invokeMethod: @(plugins_color_panel: :kClosedCallbackMethod )
142
- arguments: nil ];
145
+ [_channel invokeMethod: @(plugins_color_panel: :kClosedCallbackMethod ) arguments: nil ];
143
146
}
144
147
145
148
@end
0 commit comments