Skip to content

Commit 2354f98

Browse files
[macOS] Use FLEMethodError on color panel plugin bad arguments
1 parent 0adf81e commit 2354f98

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

plugins/color_panel/macos/FLEColorPanelPlugin.mm

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ @implementation FLEColorPanelPlugin {
2424
}
2525

2626
+ (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];
3232
[registrar addMethodCallDelegate:instance channel:channel];
3333
}
3434

35-
- (instancetype)initWithChannel:(FLEMethodChannel*)channel {
35+
- (instancetype)initWithChannel:(FLEMethodChannel *)channel {
3636
self = [super init];
3737
if (self) {
3838
_channel = channel;
@@ -45,26 +45,30 @@ - (instancetype)initWithChannel:(FLEMethodChannel*)channel {
4545
* panel channel.
4646
*/
4747
- (void)handleMethodCall:(FLEMethodCall *)call result:(FLEMethodResult)result {
48-
BOOL handled = YES;
48+
BOOL methodImplemented = YES;
4949
if ([call.methodName isEqualToString:@(plugins_color_panel::kShowColorPanelMethod)]) {
5050
if ([call.arguments isKindOfClass:[NSDictionary class]]) {
5151
BOOL showAlpha =
5252
[[call.arguments valueForKey:@(plugins_color_panel::kColorPanelShowAlpha)] boolValue];
5353
[self showColorPanelWithAlpha:showAlpha];
5454
} 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;
5963
}
6064
} else if ([call.methodName isEqualToString:@(plugins_color_panel::kHideColorPanelMethod)]) {
6165
[self hideColorPanel];
6266
} else {
63-
handled = NO;
67+
methodImplemented = NO;
6468
}
6569
// Send an immediate empty success message for handled messages, since the actual color data
6670
// will be provided in follow-up messages.
67-
result(handled ? nil : FLEMethodNotImplemented);
71+
result(methodImplemented ? nil : FLEMethodNotImplemented);
6872
}
6973

7074
/**
@@ -114,7 +118,7 @@ - (void)selectedColorDidChange {
114118
NSColor *color = [NSColorPanel sharedColorPanel].color;
115119
NSDictionary *colorDictionary = [self dictionaryWithColor:color];
116120
[_channel invokeMethod:@(plugins_color_panel::kColorSelectedCallbackMethod)
117-
arguments:colorDictionary];
121+
arguments:colorDictionary];
118122
}
119123

120124
/**
@@ -138,8 +142,7 @@ - (NSDictionary *)dictionaryWithColor:(NSColor *)color {
138142

139143
- (void)windowWillClose:(NSNotification *)notification {
140144
[self removeColorPanelConnections];
141-
[_channel invokeMethod:@(plugins_color_panel::kClosedCallbackMethod)
142-
arguments:nil];
145+
[_channel invokeMethod:@(plugins_color_panel::kClosedCallbackMethod) arguments:nil];
143146
}
144147

145148
@end

0 commit comments

Comments
 (0)