2020-02-26 14:51:02 +08:00
|
|
|
/*
|
|
|
|
* Copyright [2019] [Doric.Pub]
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
//
|
|
|
|
// DoricDevViewController.m
|
|
|
|
// Doric
|
|
|
|
//
|
|
|
|
// Created by jingpeng.wang on 2020/2/26.
|
|
|
|
//
|
|
|
|
#import <DoricCore/Doric.h>
|
|
|
|
#import <DoricCore/DoricContextManager.h>
|
2020-02-27 16:13:14 +08:00
|
|
|
#import "NSString+JsonString.h"
|
2020-02-26 14:51:02 +08:00
|
|
|
|
|
|
|
#import "DoricDev.h"
|
|
|
|
#import "DoricDevViewController.h"
|
|
|
|
#import "DoricJSRemoteExecutor.h"
|
|
|
|
#import "QRScanViewController.h"
|
|
|
|
|
|
|
|
@interface DoricDevViewController () <UITableViewDelegate, UITableViewDataSource>
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation DoricDevViewController
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2020-02-28 17:31:59 +08:00
|
|
|
|
2020-02-26 14:51:02 +08:00
|
|
|
self.title = @"Doric Devkit";
|
|
|
|
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
|
|
|
|
it.width = self.view.width;
|
|
|
|
it.height = self.view.height;
|
|
|
|
it.left = it.top = 0;
|
|
|
|
it.dataSource = self;
|
|
|
|
it.delegate = self;
|
|
|
|
}]];
|
2020-03-20 15:53:09 +08:00
|
|
|
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Disconnect" style:UIBarButtonItemStylePlain target:self action:@selector(onClose)];
|
|
|
|
self.navigationItem.rightBarButtonItem = rightBarItem;
|
2020-02-28 17:31:59 +08:00
|
|
|
if ([[DoricDev instance] isInDevMode]) {
|
|
|
|
return;
|
|
|
|
}
|
2020-02-26 14:51:02 +08:00
|
|
|
if (self.isSimulator) {
|
|
|
|
NSString *result = @"127.0.0.1";
|
|
|
|
[DoricJSRemoteExecutor configIp:result];
|
|
|
|
[[DoricDev instance] connectDevKit:[NSString stringWithFormat:@"ws://%@:7777", result]];
|
2020-04-03 10:19:13 +08:00
|
|
|
ShowToast([NSString stringWithFormat:@"Connected to %@", result], DoricGravityBottom);
|
2020-02-26 14:51:02 +08:00
|
|
|
} else {
|
|
|
|
[self.navigationController pushViewController:[QRScanViewController new] animated:NO];
|
|
|
|
}
|
|
|
|
}
|
2021-02-09 15:09:52 +08:00
|
|
|
|
2020-03-20 15:53:09 +08:00
|
|
|
- (void)onClose {
|
|
|
|
[[DoricDev instance] closeDevMode];
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
|
|
}
|
2021-02-09 15:09:52 +08:00
|
|
|
|
2020-02-26 14:51:02 +08:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
|
|
return [DoricContextManager.instance aliveContexts].count;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2021-02-09 15:09:52 +08:00
|
|
|
DoricContext *context = [DoricContextManager.instance aliveContexts][(NSUInteger) indexPath.row];
|
2020-02-26 14:51:02 +08:00
|
|
|
NSString *path = context.source;
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
|
|
|
|
if (cell == nil) {
|
|
|
|
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
}
|
2020-02-27 16:13:14 +08:00
|
|
|
cell.textLabel.text = [path stringByAppendingString:@" Debug"];
|
2020-02-26 14:51:02 +08:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isSimulator {
|
|
|
|
return TARGET_OS_SIMULATOR == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2021-02-09 15:09:52 +08:00
|
|
|
DoricContext *context = [DoricContextManager.instance aliveContexts][(NSUInteger) indexPath.row];
|
2020-02-27 16:13:14 +08:00
|
|
|
[[NSNotificationCenter defaultCenter] postNotificationName:@"StartDebugEvent" object:context.contextId];
|
|
|
|
NSDictionary *jsonDic = @{
|
2020-02-28 17:31:59 +08:00
|
|
|
@"cmd": @"DEBUG",
|
|
|
|
@"data": @{
|
|
|
|
@"contextId": context.contextId,
|
|
|
|
@"source": [context.source stringByReplacingOccurrencesOfString:@".js" withString:@".ts"]
|
|
|
|
}
|
2020-02-27 16:13:14 +08:00
|
|
|
};
|
2020-02-28 17:31:59 +08:00
|
|
|
|
2020-02-27 16:13:14 +08:00
|
|
|
NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic];
|
|
|
|
[[DoricDev instance] sendDevCommand:jsonStr];
|
2020-02-26 14:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|