diff --git a/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.h b/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.h index de7a4ae0f..81463fe01 100644 --- a/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.h +++ b/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.h @@ -6,13 +6,13 @@ * */ #import -#import +#import /** -SonarCppBridgingResponder is a simple ObjC wrapper around SonarResponder +SonarCppBridgingResponder is a simple ObjC wrapper around FlipperResponder that forwards messages to the underlying C++ responder. This class allows pure Objective-C plugins to send messages to the underlying responder. */ -@interface SonarCppBridgingResponder : NSObject +@interface SonarCppBridgingResponder : NSObject - (instancetype)initWithCppResponder:(std::unique_ptr)responder; @end diff --git a/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.mm b/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.mm index 8a1bd0f23..97908ef32 100644 --- a/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.mm +++ b/iOS/FlipperKit/CppBridge/SonarCppBridgingResponder.mm @@ -26,7 +26,7 @@ return self; } -#pragma mark - SonarResponder +#pragma mark - FlipperResponder - (void)success:(NSDictionary *)response { responder_->success(facebook::cxxutils::convertIdToFollyDynamic(response, true)); } diff --git a/iOS/FlipperKit/FlipperConnection.h b/iOS/FlipperKit/FlipperConnection.h index 7364b512b..2c48c3ad5 100644 --- a/iOS/FlipperKit/FlipperConnection.h +++ b/iOS/FlipperKit/FlipperConnection.h @@ -7,10 +7,10 @@ */ #import -@protocol SonarResponder; +@protocol FlipperResponder; @protocol SonarWebSocket; -typedef void (^SonarReceiver)(NSDictionary*, id); +typedef void (^SonarReceiver)(NSDictionary*, id); /** Represents a connection between the Desktop and mobile plugins with corresponding identifiers. diff --git a/iOS/FlipperKit/FlipperResponder.h b/iOS/FlipperKit/FlipperResponder.h new file mode 100644 index 000000000..f4940b05e --- /dev/null +++ b/iOS/FlipperKit/FlipperResponder.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + * + */ +#import + +/** +Acts as a hook for providing return values to remote called from Sonar desktop plugins. +*/ +@protocol FlipperResponder + +/** +Respond with a successful return value. +*/ +- (void)success:(NSDictionary *)response; + +/** +Respond with an error. +*/ +- (void)error:(NSDictionary *)response; + +@end diff --git a/iOS/Plugins/SonarKitLayoutPlugin/SonarKitLayoutPlugin/SonarKitLayoutPlugin.mm b/iOS/Plugins/SonarKitLayoutPlugin/SonarKitLayoutPlugin/SonarKitLayoutPlugin.mm index 098138180..59e2e75f7 100644 --- a/iOS/Plugins/SonarKitLayoutPlugin/SonarKitLayoutPlugin/SonarKitLayoutPlugin.mm +++ b/iOS/Plugins/SonarKitLayoutPlugin/SonarKitLayoutPlugin/SonarKitLayoutPlugin.mm @@ -11,7 +11,7 @@ #import #import -#import +#import #import #import "SKDescriptorMapper.h" #import "SKNodeDescriptor.h" @@ -83,15 +83,15 @@ // In order to avoid a retain cycle (Connection -> Block -> SonarKitLayoutPlugin -> Connection ...) __weak SonarKitLayoutPlugin *weakSelf = self; - [connection receive:@"getRoot" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"getRoot" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallGetRoot: responder]; }); }]; - [connection receive:@"getNodes" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"getNodes" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallGetNodes: params[@"ids"] withResponder: responder]; }); }]; - [connection receive:@"setData" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"setData" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallSetData: params[@"id"] withPath: params[@"path"] @@ -100,19 +100,19 @@ }); }]; - [connection receive:@"setHighlighted" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"setHighlighted" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallSetHighlighted: params[@"id"] withResponder: responder]; }); }]; - [connection receive:@"setSearchActive" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"setSearchActive" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallSetSearchActive: [params[@"active"] boolValue] withConnection: connection]; }); }]; - [connection receive:@"isConsoleEnabled" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"isConsoleEnabled" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [responder success: @{@"isEnabled": @NO}];}); }]; - [connection receive:@"getSearchResults" withBlock:^(NSDictionary *params, id responder) { + [connection receive:@"getSearchResults" withBlock:^(NSDictionary *params, id responder) { FlipperPerformBlockOnMainThread(^{ [weakSelf onCallGetSearchResults: params[@"query"] withResponder: responder]; }); }]; } @@ -124,13 +124,13 @@ [self onCallSetSearchActive: NO withConnection: nil]; } -- (void)onCallGetRoot:(id)responder { +- (void)onCallGetRoot:(id)responder { const auto rootNode= [self getNode: [self trackObject: _rootNode]]; [responder success: rootNode]; } -- (void)onCallGetNodes:(NSArray *)nodeIds withResponder:(id)responder { +- (void)onCallGetNodes:(NSArray *)nodeIds withResponder:(id)responder { NSMutableArray *elements = [NSMutableArray new]; for (id nodeId in nodeIds) { @@ -174,7 +174,7 @@ } } -- (void)onCallGetSearchResults:(NSString *)query withResponder:(id)responder { +- (void)onCallGetSearchResults:(NSString *)query withResponder:(id)responder { const auto alreadyAddedElements = [NSMutableSet new]; SKSearchResultNode *matchTree = [self searchForQuery:(NSString *)[query lowercaseString] fromNode:(id)_rootNode withElementsAlreadyAdded: alreadyAddedElements]; @@ -185,7 +185,7 @@ return; } -- (void)onCallSetHighlighted:(NSString *)objectId withResponder:(id)responder { +- (void)onCallSetHighlighted:(NSString *)objectId withResponder:(id)responder { if (_lastHighlightedNode != nil) { id lastHighlightedObject = [_trackedObjects objectForKey: _lastHighlightedNode]; if (lastHighlightedObject == nil) { diff --git a/iOS/SonarKit.podspec b/iOS/SonarKit.podspec index fbdf19531..c5d91ccfa 100644 --- a/iOS/SonarKit.podspec +++ b/iOS/SonarKit.podspec @@ -64,7 +64,7 @@ Pod::Spec.new do |spec| 'iOS/Plugins/SonarKitNetworkPlugin/SonarKitNetworkPlugin/SKResponseInfo.h', 'iOS/Plugins/SonarKitNetworkPlugin/SonarKitNetworkPlugin/SonarKitNetworkPlugin.h', 'iOS/FBDefines/FBMacros.h', - 'iOS/FlipperKit/**/{FlipperStateUpdateListener,FlipperClient,FlipperPlugin,FlipperConnection,SonarResponder,SKMacros}.h' + 'iOS/FlipperKit/**/{FlipperStateUpdateListener,FlipperClient,FlipperPlugin,FlipperConnection,FlipperResponder,SKMacros}.h' header_search_paths = "\"$(PODS_ROOT)/FlipperKit/iOS/FlipperKit\" \"$(PODS_ROOT)\"/Headers/Private/FlipperKit/** \"$(PODS_ROOT)/boost-for-react-native\" \"$(PODS_ROOT)/DoubleConversion\" \"$(PODS_ROOT)/PeerTalkSonar\"" ss.pod_target_xcconfig = { "USE_HEADERMAP" => "NO", "DEFINES_MODULE" => "YES", diff --git a/iOS/SonarKitTestUtils/SonarResponderMock.h b/iOS/SonarKitTestUtils/SonarResponderMock.h index 0adc1e077..28b595514 100644 --- a/iOS/SonarKitTestUtils/SonarResponderMock.h +++ b/iOS/SonarKitTestUtils/SonarResponderMock.h @@ -7,9 +7,9 @@ */ #import -#import +#import -@interface SonarResponderMock : NSObject +@interface SonarResponderMock : NSObject @property (nonatomic, readonly) NSArray *successes; @property (nonatomic, readonly) NSArray *errors;