function complete

This commit is contained in:
王劲鹏 2020-02-27 16:13:14 +08:00 committed by osborn
parent f9f48d9c8a
commit 9764e720fc
8 changed files with 101 additions and 15 deletions

View File

@ -23,12 +23,6 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "DoricDriverProtocol.h" #import "DoricDriverProtocol.h"
typedef NS_ENUM(NSInteger, DoricQueueMode) {
JS = 0,
UI,
INDEPENDENT
};
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
@interface DoricDebugDriver : NSObject <DoricDriverProtocol> @interface DoricDebugDriver : NSObject <DoricDriverProtocol>

View File

@ -19,18 +19,31 @@
// //
// Created by jingpeng.wang on 2020/2/25. // Created by jingpeng.wang on 2020/2/25.
// //
#import <DoricCore/Doric.h>
#import <DoricCore/DoricContextManager.h>
#import <DoricCore/DoricNativeDriver.h>
#import "DoricDev.h" #import "DoricDev.h"
#import "DoricWSClient.h" #import "DoricWSClient.h"
#import "DoricDebugDriver.h"
@interface DoricDev () @interface DoricDev ()
@property(nonatomic, strong) DoricWSClient *wsclient; @property(nonatomic, strong) DoricWSClient *wsclient;
@property(nonatomic, strong) DoricContext *context;
@property(nonatomic, strong) DoricDebugDriver *driver;
@end @end
@implementation DoricDev @implementation DoricDev
- (instancetype)init { - (instancetype)init {
if (self = [super init]) { if (self = [super init]) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onOpenEvent) name:@"OpenEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEOFEvent) name:@"EOFEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onConnectExceptionEvent) name:@"ConnectExceptionEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStartDebugEvent:) name:@"StartDebugEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onEnterDebugEvent) name:@"EnterDebugEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onStopDebugEvent) name:@"StopDebugEvent" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDebuggerReadyEvent) name:@"DebuggerReadyEvent" object:nil];
} }
return self; return self;
} }
@ -62,4 +75,41 @@ - (void)disconnectDevKit {
} }
} }
- (void)onOpenEvent {
ShowToast(@"dev kit connected", BOTTOM);
}
- (void)onEOFEvent {
ShowToast(@"dev kit eof exception", BOTTOM);
}
- (void)onConnectExceptionEvent {
ShowToast(@"dev kit connection exception", BOTTOM);
}
- (void)onStartDebugEvent:(NSNotification *)notification {
NSString *contextId = notification.object;
ShowToast(contextId, BOTTOM);
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
DoricContext *context = value.nonretainedObjectValue;
BOOL result = [context.contextId compare:contextId] == NSOrderedSame;
if (result) {
_context = context;
}
}
}
- (void)onEnterDebugEvent {
_driver = [DoricDebugDriver new];
}
- (void)onStopDebugEvent {
_context.driver = [DoricNativeDriver instance];
[_context reInit];
}
- (void)onDebuggerReadyEvent {
_context.driver = _driver;
[_context reInit];
}
@end @end

View File

@ -21,6 +21,7 @@
// //
#import <DoricCore/Doric.h> #import <DoricCore/Doric.h>
#import <DoricCore/DoricContextManager.h> #import <DoricCore/DoricContextManager.h>
#import "NSString+JsonString.h"
#import "DoricDev.h" #import "DoricDev.h"
#import "DoricDevViewController.h" #import "DoricDevViewController.h"
@ -67,7 +68,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"]; cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellID"];
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
} }
cell.textLabel.text = path; cell.textLabel.text = [path stringByAppendingString:@" Debug"];
return cell; return cell;
} }
@ -76,6 +77,19 @@ - (BOOL)isSimulator {
} }
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSValue *value = [DoricContextManager.instance aliveContexts][(NSUInteger) indexPath.row];
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"]
}
};
NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic];
[[DoricDev instance] sendDevCommand:jsonStr];
} }
@end @end

View File

@ -54,6 +54,7 @@ - (instancetype)init {
- (void)webSocketDidOpen:(SRWebSocket *)webSocket { - (void)webSocketDidOpen:(SRWebSocket *)webSocket {
DoricLog(@"debugger webSocketDidOpen"); DoricLog(@"debugger webSocketDidOpen");
DC_UNLOCK(self.semaphore); DC_UNLOCK(self.semaphore);
[[NSNotificationCenter defaultCenter] postNotificationName:@"DebuggerReadyEvent" object:nil];
} }
- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload { - (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload {
@ -116,6 +117,7 @@ - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean {
DoricLog(@"debugger webSocketdidCloseWithCode"); DoricLog(@"debugger webSocketdidCloseWithCode");
[[NSNotificationCenter defaultCenter] postNotificationName:@"StopDebugEvent" object:nil];
} }
#pragma mark - DoricJSExecutorProtocol #pragma mark - DoricJSExecutorProtocol

View File

@ -41,6 +41,7 @@ - (instancetype)initWithUrl:(NSString *)url {
- (void)webSocketDidOpen:(SRWebSocket *)webSocket { - (void)webSocketDidOpen:(SRWebSocket *)webSocket {
DoricLog(@"webSocketDidOpen"); DoricLog(@"webSocketDidOpen");
[[NSNotificationCenter defaultCenter] postNotificationName:@"OpenEvent" object:nil];
} }
- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload { - (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload {
@ -57,22 +58,29 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message {
DoricLog(@"webSocketdidReceiveMessage parse error%@", err); DoricLog(@"webSocketdidReceiveMessage parse error%@", err);
return; return;
} }
NSString *source = [[dic valueForKey:@"source"] mutableCopy]; NSString *cmd = [[dic valueForKey:@"cmd"] mutableCopy];
NSString *script = [dic valueForKey:@"script"]; if ([cmd compare:@"SWITCH_TO_DEBUG"] == NSOrderedSame) {
for (NSValue *value in [[DoricContextManager instance] aliveContexts]) { [[NSNotificationCenter defaultCenter] postNotificationName:@"EnterDebugEvent" object:nil];
DoricContext *context = value.nonretainedObjectValue; } else if ([cmd compare:@"RELOAD"] == NSOrderedSame) {
if ([source containsString:context.source]) { // NSString *source = [[dic valueForKey:@"source"] mutableCopy];
[context reload:script]; // NSString *script = [dic valueForKey:@"script"];
} // for (NSValue *value in [[DoricContextManager instance] aliveContexts]) {
// DoricContext *context = value.nonretainedObjectValue;
// if ([source containsString:context.source]) {
// [context reload:script];
// }
// }
} }
} }
- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { - (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error {
DoricLog(@"webSocketdidFailWithError"); DoricLog(@"webSocketdidFailWithError");
[[NSNotificationCenter defaultCenter] postNotificationName:@"ConnectExceptionEvent" object:nil];
} }
- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { - (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean {
DoricLog(@"webSocketdidCloseWithCode"); DoricLog(@"webSocketdidCloseWithCode");
[[NSNotificationCenter defaultCenter] postNotificationName:@"EOFEvent" object:nil];
} }
- (void)send:(NSString *)command { - (void)send:(NSString *)command {

View File

@ -68,7 +68,17 @@ - (BOOL)isSimulator {
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { if (indexPath.row == 0) {
NSString *file = self.demoFilePaths[44];
DoricViewController *doricViewController = [[DoricViewController alloc]
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
alias:self.demoFilePaths[44]
extra:nil
];
[self.navigationController pushViewController:doricViewController animated:NO];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController pushViewController:[DoricDevViewController new] animated:NO]; [self.navigationController pushViewController:[DoricDevViewController new] animated:NO];
}
);
return; return;
} }
NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row]; NSString *file = self.demoFilePaths[(NSUInteger) indexPath.row];

View File

@ -55,6 +55,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)reload:(NSString *)script; - (void)reload:(NSString *)script;
- (void)reInit;
- (void)onShow; - (void)onShow;
- (void)onHidden; - (void)onHidden;

View File

@ -96,6 +96,12 @@ - (void)reload:(NSString *)script {
[self onShow]; [self onShow];
} }
- (void)reInit {
self.rootNode.viewId = nil;
[self callEntity:DORIC_ENTITY_INIT, self.initialParams, nil];
[self callEntity:DORIC_ENTITY_CREATE, nil];
}
- (void)onShow { - (void)onShow {
[self callEntity:DORIC_ENTITY_SHOW, nil]; [self callEntity:DORIC_ENTITY_SHOW, nil];
} }