iOS:optimize API
This commit is contained in:
@@ -25,11 +25,16 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@interface DoricDev : NSObject
|
||||
+ (instancetype)instance;
|
||||
|
||||
- (void)openDevMode;
|
||||
|
||||
- (void)closeDevMode;
|
||||
|
||||
- (BOOL)isInDevMode;
|
||||
|
||||
- (void)connectDevKit:(NSString *)url;
|
||||
|
||||
- (void)sendDevCommand:(NSString *)command;
|
||||
|
||||
- (void)disconnectDevKit;
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
@@ -27,6 +27,7 @@
|
||||
#import "DoricDev.h"
|
||||
#import "DoricWSClient.h"
|
||||
#import "DoricDebugDriver.h"
|
||||
#import "DoricDevViewController.h"
|
||||
|
||||
@interface DoricDev ()
|
||||
@property(nonatomic, strong) DoricWSClient *wsclient;
|
||||
@@ -58,6 +59,30 @@ + (instancetype)instance {
|
||||
return _instance;
|
||||
}
|
||||
|
||||
- (void)openDevMode {
|
||||
DoricDevViewController *devViewController = [DoricDevViewController new];
|
||||
|
||||
UIViewController *viewController = [UIApplication sharedApplication].delegate.window.rootViewController;
|
||||
UINavigationController *navigationController;
|
||||
if ([viewController isKindOfClass:[UINavigationController class]]) {
|
||||
navigationController = (UINavigationController *) viewController;
|
||||
} else {
|
||||
navigationController = viewController.navigationController;
|
||||
}
|
||||
[navigationController pushViewController:devViewController animated:NO];
|
||||
}
|
||||
|
||||
- (void)closeDevMode {
|
||||
if (self.wsclient) {
|
||||
[self.wsclient close];
|
||||
self.wsclient = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)isInDevMode {
|
||||
return self.wsclient != nil;
|
||||
}
|
||||
|
||||
- (void)connectDevKit:(NSString *)url {
|
||||
if (self.wsclient) {
|
||||
[self.wsclient close];
|
||||
@@ -69,13 +94,6 @@ - (void)sendDevCommand:(NSString *)command {
|
||||
[self.wsclient send:command];
|
||||
}
|
||||
|
||||
- (void)disconnectDevKit {
|
||||
if (self.wsclient) {
|
||||
[self.wsclient close];
|
||||
self.wsclient = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onOpenEvent {
|
||||
ShowToast(@"dev kit connected", BOTTOM);
|
||||
}
|
||||
|
@@ -35,7 +35,7 @@ @implementation DoricDevViewController
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
|
||||
|
||||
self.title = @"Doric Devkit";
|
||||
[self.view addSubview:[[UITableView new] also:^(UITableView *it) {
|
||||
it.width = self.view.width;
|
||||
@@ -44,7 +44,9 @@ - (void)viewDidLoad {
|
||||
it.dataSource = self;
|
||||
it.delegate = self;
|
||||
}]];
|
||||
|
||||
if ([[DoricDev instance] isInDevMode]) {
|
||||
return;
|
||||
}
|
||||
if (self.isSimulator) {
|
||||
NSString *result = @"127.0.0.1";
|
||||
[DoricJSRemoteExecutor configIp:result];
|
||||
@@ -81,13 +83,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
||||
DoricContext *context = value.nonretainedObjectValue;
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"StartDebugEvent" object:context.contextId];
|
||||
NSDictionary *jsonDic = @{
|
||||
@"cmd": @"DEBUG",
|
||||
@"data": @{
|
||||
@"contextId": context.contextId,
|
||||
@"source": [context.source stringByReplacingOccurrencesOfString:@".js" withString:@".ts"]
|
||||
}
|
||||
@"cmd": @"DEBUG",
|
||||
@"data": @{
|
||||
@"contextId": context.contextId,
|
||||
@"source": [context.source stringByReplacingOccurrencesOfString:@".js" withString:@".ts"]
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic];
|
||||
[[DoricDev instance] sendDevCommand:jsonStr];
|
||||
}
|
||||
|
@@ -62,14 +62,14 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
|
||||
if ([cmd compare:@"SWITCH_TO_DEBUG"] == NSOrderedSame) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:@"EnterDebugEvent" object:nil];
|
||||
} else if ([cmd compare:@"RELOAD"] == NSOrderedSame) {
|
||||
// NSString *source = [[dic valueForKey:@"source"] mutableCopy];
|
||||
// NSString *script = [dic valueForKey:@"script"];
|
||||
// for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
|
||||
// DoricContext *context = value.nonretainedObjectValue;
|
||||
// if ([source containsString:context.source]) {
|
||||
// [context reload:script];
|
||||
// }
|
||||
// }
|
||||
NSString *source = [[dic valueForKey:@"source"] mutableCopy];
|
||||
NSString *script = [dic valueForKey:@"script"];
|
||||
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
|
||||
DoricContext *context = value.nonretainedObjectValue;
|
||||
if ([source containsString:context.source]) {
|
||||
[context reload:script];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user