|
|
|
@@ -26,27 +26,131 @@
|
|
|
|
|
#import "DoricDevViewController.h"
|
|
|
|
|
#import "QRScanViewController.h"
|
|
|
|
|
|
|
|
|
|
@interface DoricDevViewController () <UITableViewDelegate, UITableViewDataSource>
|
|
|
|
|
@interface DoricDevViewController () <UITableViewDelegate, UITableViewDataSource, DoricDevStatusCallback>
|
|
|
|
|
@property(nonatomic, strong) UIView *headerView;
|
|
|
|
|
@property(nonatomic, strong) UILabel *tvLabel;
|
|
|
|
|
@property(nonatomic, strong) UILabel *tvConnection;
|
|
|
|
|
@property(nonatomic, strong) UILabel *tvInput;
|
|
|
|
|
@property(nonatomic, strong) UILabel *tvScan;
|
|
|
|
|
@property(nonatomic, strong) UILabel *tvDisconnect;
|
|
|
|
|
|
|
|
|
|
@property(nonatomic, strong) UITableView *listView;
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation DoricDevViewController
|
|
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
|
[super viewDidLoad];
|
|
|
|
|
|
|
|
|
|
self.title = @"Doric Devkit";
|
|
|
|
|
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
|
|
|
|
|
self.view.backgroundColor = UIColor.whiteColor;
|
|
|
|
|
self.headerView = [[UIView new] also:^(UIView *it) {
|
|
|
|
|
it.width = self.view.width;
|
|
|
|
|
it.height = self.view.height;
|
|
|
|
|
it.left = it.top = 0;
|
|
|
|
|
it.dataSource = self;
|
|
|
|
|
it.delegate = self;
|
|
|
|
|
}]];
|
|
|
|
|
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Disconnect" style:UIBarButtonItemStylePlain target:self action:@selector(onClose)];
|
|
|
|
|
self.navigationItem.rightBarButtonItem = rightBarItem;
|
|
|
|
|
if ([[DoricDev instance] isInDevMode]) {
|
|
|
|
|
return;
|
|
|
|
|
it.height = 60;
|
|
|
|
|
it.backgroundColor = DoricColor(@(0xff70a1ff));
|
|
|
|
|
[self.view addSubview:it];
|
|
|
|
|
}];
|
|
|
|
|
self.tvLabel = [[UILabel new] also:^(UILabel *it) {
|
|
|
|
|
it.text = @"Devkit";
|
|
|
|
|
it.textColor = [UIColor whiteColor];
|
|
|
|
|
it.font = [UIFont systemFontOfSize:30];
|
|
|
|
|
it.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
[it sizeToFit];
|
|
|
|
|
it.centerY = self.headerView.centerY;
|
|
|
|
|
it.left = 15;
|
|
|
|
|
[self.headerView addSubview:it];
|
|
|
|
|
}];
|
|
|
|
|
self.tvConnection = [[UILabel new] also:^(UILabel *it) {
|
|
|
|
|
it.text = @"Disconnected";
|
|
|
|
|
it.textColor = [UIColor whiteColor];
|
|
|
|
|
it.font = [UIFont systemFontOfSize:12];
|
|
|
|
|
it.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
[it sizeToFit];
|
|
|
|
|
[self.headerView addSubview:it];
|
|
|
|
|
}];
|
|
|
|
|
self.tvInput = [[UILabel new] also:^(UILabel *it) {
|
|
|
|
|
it.text = @"Input";
|
|
|
|
|
it.textColor = [UIColor whiteColor];
|
|
|
|
|
it.font = [UIFont systemFontOfSize:15];
|
|
|
|
|
it.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
[it sizeToFit];
|
|
|
|
|
it.width += 30;
|
|
|
|
|
it.height += 10;
|
|
|
|
|
it.backgroundColor = DoricColor(@(0xff1abc9c));
|
|
|
|
|
[self.headerView addSubview:it];
|
|
|
|
|
it.userInteractionEnabled = YES;
|
|
|
|
|
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(input)];
|
|
|
|
|
[it addGestureRecognizer:tapGestureRecognizer];
|
|
|
|
|
}];
|
|
|
|
|
self.tvScan = [[UILabel new] also:^(UILabel *it) {
|
|
|
|
|
it.text = @"Scan";
|
|
|
|
|
it.textColor = [UIColor whiteColor];
|
|
|
|
|
it.font = [UIFont systemFontOfSize:15];
|
|
|
|
|
it.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
[it sizeToFit];
|
|
|
|
|
it.width += 30;
|
|
|
|
|
it.height += 10;
|
|
|
|
|
it.backgroundColor = DoricColor(@(0xff1abc9c));
|
|
|
|
|
[self.headerView addSubview:it];
|
|
|
|
|
it.userInteractionEnabled = YES;
|
|
|
|
|
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(scan)];
|
|
|
|
|
[it addGestureRecognizer:tapGestureRecognizer];
|
|
|
|
|
}];
|
|
|
|
|
self.tvDisconnect = [[UILabel new] also:^(UILabel *it) {
|
|
|
|
|
it.text = @"Disconnect";
|
|
|
|
|
it.textColor = [UIColor whiteColor];
|
|
|
|
|
it.font = [UIFont systemFontOfSize:15];
|
|
|
|
|
it.textAlignment = NSTextAlignmentCenter;
|
|
|
|
|
[it sizeToFit];
|
|
|
|
|
it.width += 30;
|
|
|
|
|
it.height += 10;
|
|
|
|
|
it.backgroundColor = DoricColor(@(0xff95a5a6));
|
|
|
|
|
[self.headerView addSubview:it];
|
|
|
|
|
it.userInteractionEnabled = YES;
|
|
|
|
|
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(disconnect)];
|
|
|
|
|
[it addGestureRecognizer:tapGestureRecognizer];
|
|
|
|
|
}];
|
|
|
|
|
[self initHeaders];
|
|
|
|
|
[DoricDev.instance addStatusCallback:self];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)disconnect {
|
|
|
|
|
[DoricDev.instance closeDevMode];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)input {
|
|
|
|
|
if (self.isSimulator) {
|
|
|
|
|
NSString *result = @"127.0.0.1";
|
|
|
|
|
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
|
|
|
|
ShowToast([NSString stringWithFormat:@"Connected to %@", result], DoricGravityBottom);
|
|
|
|
|
} else {
|
|
|
|
|
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Please input devkit ip"
|
|
|
|
|
message:@""
|
|
|
|
|
preferredStyle:UIAlertControllerStyleAlert];
|
|
|
|
|
[alert addTextFieldWithConfigurationHandler:^(UITextField *_Nonnull textField) {
|
|
|
|
|
textField.placeholder = @"192.168.1.1";
|
|
|
|
|
}];
|
|
|
|
|
__weak typeof(alert) _alert = alert;
|
|
|
|
|
|
|
|
|
|
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil)
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:nil];
|
|
|
|
|
[alert addAction:cancelAction];
|
|
|
|
|
|
|
|
|
|
UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil)
|
|
|
|
|
style:UIAlertActionStyleDefault
|
|
|
|
|
handler:^(UIAlertAction *action) {
|
|
|
|
|
__strong typeof(_alert) alert = _alert;
|
|
|
|
|
NSString *ip = alert.textFields.lastObject.text;
|
|
|
|
|
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", ip]];
|
|
|
|
|
}];
|
|
|
|
|
[alert addAction:okAction];
|
|
|
|
|
|
|
|
|
|
[self presentViewController:alert animated:YES completion:nil];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)scan {
|
|
|
|
|
if (self.isSimulator) {
|
|
|
|
|
NSString *result = @"127.0.0.1";
|
|
|
|
|
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
|
|
|
@@ -56,9 +160,40 @@ - (void)viewDidLoad {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onClose {
|
|
|
|
|
[[DoricDev instance] closeDevMode];
|
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
|
- (void)initHeaders {
|
|
|
|
|
if (DoricDev.instance.isInDevMode) {
|
|
|
|
|
self.tvConnection.text = DoricDev.instance.ip;
|
|
|
|
|
self.tvInput.hidden = YES;
|
|
|
|
|
self.tvScan.hidden = YES;
|
|
|
|
|
self.tvDisconnect.hidden = NO;
|
|
|
|
|
self.tvConnection.backgroundColor = DoricColor(@(0xff2ed573));
|
|
|
|
|
|
|
|
|
|
[self.tvConnection sizeToFit];
|
|
|
|
|
self.tvConnection.width += 20;
|
|
|
|
|
self.tvConnection.height += 6;
|
|
|
|
|
|
|
|
|
|
self.tvConnection.left = self.tvLabel.right + 20;
|
|
|
|
|
self.tvDisconnect.right = self.view.width - 15;
|
|
|
|
|
self.tvConnection.centerY = self.headerView.centerY;
|
|
|
|
|
self.tvDisconnect.centerY = self.headerView.centerY;
|
|
|
|
|
} else {
|
|
|
|
|
self.tvConnection.text = @"Disconnected";
|
|
|
|
|
self.tvInput.hidden = NO;
|
|
|
|
|
self.tvScan.hidden = NO;
|
|
|
|
|
self.tvDisconnect.hidden = YES;
|
|
|
|
|
self.tvConnection.backgroundColor = DoricColor(@(0xffa4b0be));
|
|
|
|
|
|
|
|
|
|
[self.tvConnection sizeToFit];
|
|
|
|
|
self.tvConnection.width += 20;
|
|
|
|
|
self.tvConnection.height += 6;
|
|
|
|
|
|
|
|
|
|
self.tvConnection.left = self.tvLabel.right + 20;
|
|
|
|
|
self.tvScan.right = self.view.width - 15;
|
|
|
|
|
self.tvInput.right = self.tvScan.left - 10;
|
|
|
|
|
self.tvConnection.centerY = self.headerView.centerY;
|
|
|
|
|
self.tvScan.centerY = self.headerView.centerY;
|
|
|
|
|
self.tvInput.centerY = self.headerView.centerY;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
@@ -93,4 +228,29 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onOpen:(NSString *)url {
|
|
|
|
|
[self initHeaders];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onClose:(NSString *)url {
|
|
|
|
|
[self initHeaders];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onFailure:(NSError *)error {
|
|
|
|
|
[self initHeaders];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onReload:(DoricContext *)context script:(NSString *)script {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onStartDebugging:(DoricContext *)context {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void)onStopDebugging {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|