fix:iOS Runloop cannot exit and other issues
This commit is contained in:
parent
627f323ae3
commit
e78625281f
@ -212,6 +212,7 @@ public class DoricContext {
|
||||
this.script = script;
|
||||
this.mRootNode.setId("");
|
||||
this.mRootNode.clearSubModel();
|
||||
this.mRootNode.getView().removeAllViews();
|
||||
getDriver().createContext(mContextId, script, source);
|
||||
init(this.extra);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_CREATE);
|
||||
|
@ -205,9 +205,9 @@ - (void)startDebugging:(NSString *)source {
|
||||
[self.wsClient sendToDebugger:@"DEBUG_RES" payload:@{
|
||||
@"contextId": context.contextId
|
||||
}];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.debuggable = [[DoricContextDebuggable alloc] initWithWSClient:self.wsClient context:context];
|
||||
[self.debuggable startDebug];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
for (id <DoricDevStatusCallback> callback in self.callbacks) {
|
||||
[callback onStartDebugging:context];
|
||||
}
|
||||
@ -224,9 +224,9 @@ - (void)stopDebugging:(BOOL)resume {
|
||||
[self.wsClient sendToDebugger:@"DEBUG_STOP" payload:@{
|
||||
@"msg": @"Stop debugging"
|
||||
}];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.debuggable stopDebug:resume];
|
||||
self.debuggable = nil;
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
for (id <DoricDevStatusCallback> callback in self.callbacks) {
|
||||
[callback onStopDebugging];
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ @interface DoricRemoteJSExecutor () <DoricWSClientInterceptor>
|
||||
@property(nonatomic) NSInteger counter;
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, dispatch_semaphore_t> *semaphores;
|
||||
@property(nonatomic, strong) NSMutableDictionary <NSNumber *, JSValue *> *results;
|
||||
@property(nonatomic, strong) JSContext *jsContext;
|
||||
@end
|
||||
|
||||
@implementation DoricRemoteJSExecutor
|
||||
@ -63,6 +64,7 @@ - (instancetype)initWithWSClient:(DoricWSClient *)wsClient {
|
||||
_semaphores = [NSMutableDictionary new];
|
||||
_results = [NSMutableDictionary new];
|
||||
_counter = 0;
|
||||
_jsContext = [[JSContext alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@ -169,7 +171,9 @@ - (BOOL)interceptType:(NSString *)type command:(NSString *)cmd payload:(NSDictio
|
||||
NSString *name = payload[@"name"];
|
||||
NSArray *argsArr = payload[@"arguments"];
|
||||
id tmpBlk = self.blockMDic[name];
|
||||
if (argsArr.count == 0) {
|
||||
if (!tmpBlk) {
|
||||
DoricLog(@"Cannot find inject function:%@", name);
|
||||
} else if (argsArr.count == 0) {
|
||||
((Block0) tmpBlk)();
|
||||
} else if (argsArr.count == 1) {
|
||||
((Block1) tmpBlk)(argsArr[0]);
|
||||
@ -187,7 +191,7 @@ - (BOOL)interceptType:(NSString *)type command:(NSString *)cmd payload:(NSDictio
|
||||
} else if ([cmd isEqualToString:@"invokeMethod"]) {
|
||||
NSNumber *callId = payload[@"callId"];
|
||||
@try {
|
||||
JSValue *value = [JSValue valueWithObject:payload[@"result"] inContext:nil];
|
||||
JSValue *value = [JSValue valueWithObject:payload[@"result"] inContext:self.jsContext];
|
||||
self.results[callId] = value;
|
||||
} @catch (NSException *exception) {
|
||||
DoricLog(@"debugger ", NSStringFromSelector(_cmd), exception.reason);
|
||||
|
@ -38,6 +38,7 @@ - (instancetype)initWithUrl:(NSString *)url {
|
||||
_interceptors = [NSHashTable hashTableWithOptions:NSPointerFunctionsWeakMemory];
|
||||
_websocket = [[SRWebSocket alloc] initWithURL:[NSURL URLWithString:url]];
|
||||
_websocket.delegate = self;
|
||||
_websocket.delegateDispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
|
||||
[_websocket open];
|
||||
}
|
||||
return self;
|
||||
|
@ -102,6 +102,9 @@ - (void)reload:(NSString *)script {
|
||||
[self.driver destroyContext:self.contextId];
|
||||
self.rootNode.viewId = nil;
|
||||
[self.rootNode clearSubModel];
|
||||
[self.rootNode.view.subviews forEach:^(__kindof UIView *obj) {
|
||||
[obj removeFromSuperview];
|
||||
}];
|
||||
self.script = script;
|
||||
[self.driver createContext:self.contextId script:script source:self.source];
|
||||
[self init:self.extra];
|
||||
|
@ -103,6 +103,9 @@ - (instancetype)init {
|
||||
|
||||
- (void)teardown {
|
||||
_destroyed = YES;
|
||||
//To ensure runloop continue.
|
||||
[self ensureRunOnJSThread:^{
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)ensureRunOnJSThread:(dispatch_block_t)block {
|
||||
|
Reference in New Issue
Block a user