From 21888157df770e4f6bc44fca887cfa7e72296fbd Mon Sep 17 00:00:00 2001 From: John Knox Date: Mon, 20 Aug 2018 05:06:21 -0700 Subject: [PATCH] iOS: Add very basic diagnostic screen Summary: Adds an extremely barebones in-app screen for showing sonar diagnostics. The UI is laughable, but it's wired up. Leaving proper design to a later commit. Like in the android case, state is currently passed as a string, but will become something much more structured after this is in place. Reviewed By: priteshrnandgaonkar Differential Revision: D9218766 fbshipit-source-id: 4889ed79b928056a67b1e8cb8a40a9bd52e084f1 --- .../FlipperDiagnosticsViewController.h | 17 ++++++++ .../FlipperDiagnosticsViewController.m | 39 +++++++++++++++++++ iOS/SonarKit/SonarClient.h | 5 +++ iOS/SonarKit/SonarClient.mm | 4 ++ 4 files changed, 65 insertions(+) create mode 100644 iOS/SonarKit/FlipperDiagnosticsViewController.h create mode 100644 iOS/SonarKit/FlipperDiagnosticsViewController.m diff --git a/iOS/SonarKit/FlipperDiagnosticsViewController.h b/iOS/SonarKit/FlipperDiagnosticsViewController.h new file mode 100644 index 000000000..a729dd827 --- /dev/null +++ b/iOS/SonarKit/FlipperDiagnosticsViewController.h @@ -0,0 +1,17 @@ +/* + * 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. + * + */ +#ifdef FB_SONARKIT_ENABLED + +#import + +@interface FlipperDiagnosticsViewController : UIViewController +@property(strong, nonatomic) UIScrollView *scrollView; +@property(strong, nonatomic) UILabel *stateLabel; +@end + +#endif diff --git a/iOS/SonarKit/FlipperDiagnosticsViewController.m b/iOS/SonarKit/FlipperDiagnosticsViewController.m new file mode 100644 index 000000000..01342238a --- /dev/null +++ b/iOS/SonarKit/FlipperDiagnosticsViewController.m @@ -0,0 +1,39 @@ +#ifdef FB_SONARKIT_ENABLED + +#import "FlipperDiagnosticsViewController.h" +#import "SonarClient.h" + +@implementation FlipperDiagnosticsViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + + UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 50)]; + text.text = @"Flipper Diagnostics"; + [self.view addSubview:text]; + + self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, self.view.frame.size.height - 50)]; + self.stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 1000)]; + self.stateLabel.numberOfLines = 0; + self.stateLabel.text = [[SonarClient sharedClient] getState]; + [self.scrollView addSubview:self.stateLabel]; + self.scrollView.contentSize = self.stateLabel.frame.size; + [self.view addSubview:self.scrollView]; +} + +- (void)onUpdate { + self.stateLabel.text = [[SonarClient sharedClient] getState]; + self.scrollView.contentSize = self.stateLabel.frame.size; +} + +- (UIInterfaceOrientationMask)supportedInterfaceOrientations { + return UIInterfaceOrientationMaskPortrait; +} + +- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { + return UIInterfaceOrientationMaskPortrait; +} + +@end + +#endif diff --git a/iOS/SonarKit/SonarClient.h b/iOS/SonarKit/SonarClient.h index a3fc4b9f5..a8bbb48d4 100644 --- a/iOS/SonarKit/SonarClient.h +++ b/iOS/SonarKit/SonarClient.h @@ -45,6 +45,11 @@ Stop the connection to the Sonar desktop. */ - (void)stop; +/** +Get the current state of the sonar client +*/ +- (NSString *)getState; + // initializers are disabled. You must use `+[SonarClient sharedClient]` instance. - (instancetype)init NS_UNAVAILABLE; + (instancetype)new NS_UNAVAILABLE; diff --git a/iOS/SonarKit/SonarClient.mm b/iOS/SonarKit/SonarClient.mm index b94d858cd..a7400102e 100644 --- a/iOS/SonarKit/SonarClient.mm +++ b/iOS/SonarKit/SonarClient.mm @@ -121,6 +121,10 @@ using WrapperPlugin = facebook::sonar::SonarCppWrapperPlugin; #endif } +- (NSString *)getState { + return @(_cppClient->getState().c_str()); +} + @end #endif