Skip to content

Commit

Permalink
*[ios]add LogLevel control and RemoteDebug control
Browse files Browse the repository at this point in the history
  • Loading branch information
yangshengtao committed Aug 18, 2016
1 parent ec5277d commit 164abf8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 16 deletions.
10 changes: 9 additions & 1 deletion ios/WXDevtool/WXDevTool/Source/DerivedSources/WXDebugDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@
#import "PDDebugger.h"
#import "WXDevtool.h"

@protocol WXDebugCommandDelegate;

@interface WXDebugDomain : PDDynamicDebuggerDomain

@property (nonatomic, assign) id <PDCommandDelegate>delegate;
@property (nonatomic, assign) id <WXDebugCommandDelegate, PDCommandDelegate>delegate;

@end

@protocol WXDebugCommandDelegate <PDCommandDelegate>
@optional
- (void)domain:(WXDebugDomain *)domain sendLogLevel:(NSString *)level WithCallback:(void (^)(id error))callback;

@end
12 changes: 9 additions & 3 deletions ios/WXDevtool/WXDevTool/Source/DerivedSources/WXDebugDomain.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ + (NSString *)domainName {
- (void)handleMethodWithName:(NSString *)methodName parameters:(NSDictionary *)params responseCallback:(PDResponseCallback)responseCallback {
if ([methodName isEqualToString:@"enable"] && [self.delegate respondsToSelector:@selector(domain:enableWithCallback:)]) {
[self.delegate domain:self enableWithCallback:^(id error) {
NSMutableDictionary *params = [[NSMutableDictionary alloc] initWithCapacity:2];
[params setObject:[NSNumber numberWithBool:YES] forKey:@"WXDebug_result"];
responseCallback(params, error);
responseCallback(nil, error);
}];
} else if ([methodName isEqualToString:@"setLogLevel"] && [self.delegate respondsToSelector:@selector(domain:sendLogLevel:WithCallback:)]) {
[self.delegate domain:self sendLogLevel:[params objectForKey:@"logLevel"] WithCallback:^(id error) {
responseCallback(nil,error);
}];
} else if ([methodName isEqualToString:@"disable"] && [self.delegate respondsToSelector:@selector(domain:disableWithCallback:)]) {
[self.delegate domain:self disableWithCallback:^(id error) {
responseCallback(nil,error);
}];
}
}
Expand Down
20 changes: 9 additions & 11 deletions ios/WXDevtool/WXDevTool/Source/PonyDebugger/PDDebugger.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,6 @@ - (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(NSString *)message
if (result) {
NSMutableDictionary *newResult = [[NSMutableDictionary alloc] initWithCapacity:result.count];
[result enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) {
if ([key isEqualToString:@"WXDebug_result"]) {
[WXDevToolType setDebug:YES];
[WXSDKEngine restart];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
return;
}
[newResult setObject:[val PD_JSONObjectCopy] forKey:key];
}];
[response setObject:newResult forKey:@"result"];
Expand Down Expand Up @@ -329,10 +323,8 @@ - (void)autoConnectToBonjourServiceNamed:(NSString*)serviceName;
- (void)connectToURL:(NSURL *)url;
{
NSLog(@"Connecting to %@", url);
if ([WXDevToolType isDebug]) {
[WXDevToolType setDebug:NO];
[WXSDKEngine restart];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
if (_socket && _isConnect) {
return;
}
_msgAry = nil;
_msgAry = [NSMutableArray array];
Expand Down Expand Up @@ -663,7 +655,13 @@ - (NSString *)_deviceName


- (void)_registerDeviceWithParams:(id)params {
NSDictionary *obj = [[NSDictionary alloc] initWithObjectsAndKeys:@"WxDebug.registerDevice", @"method", [params PD_JSONObject], @"params",[NSNumber numberWithInt:0],@"id",nil];
NSDictionary *obj = [[NSDictionary alloc] initWithObjectsAndKeys:
@"WxDebug.registerDevice", @"method",
[params PD_JSONObject], @"params",
[NSNumber numberWithInt:0],@"id",
[WXLog logLevelString] ?: @"error",@"logLevel",
[NSNumber numberWithBool:[WXDevToolType isDebug]],@"remoteDebug",
nil];

NSData *data = [NSJSONSerialization dataWithJSONObject:obj options:0 error:nil];
NSString *encodedData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
*/

#import "WXDebugDomainController.h"
#import "WXDevToolType.h"
#import <WeexSDK/WXLog.h>
#import <WeexSDK/WXSDKEngine.h>

@implementation WXDebugDomainController
@dynamic domain;
Expand All @@ -24,13 +27,41 @@ + (Class)domainClass {
return [WXDebugDomain class];
}

+ (NSDictionary *)getLogLevelMap {
NSDictionary *logLevelEnumToString =
@{
@"all":@(WXLogLevelDebug),
@"error":@(WXLogLevelError),
@"warn":@(WXLogLevelWarning),
@"info":@(WXLogLevelInfo),
@"log":@(WXLogLevelLog),
@"debug":@(WXLogLevelDebug),
@"off":@(WXLogLevelOff)
};
return logLevelEnumToString;
}

#pragma mark - PDCommandDelegate
- (void)domain:(PDDynamicDebuggerDomain *)domain enableWithCallback:(void (^)(id error))callback {
[WXDevToolType setDebug:YES];
[WXSDKEngine restart];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
callback(nil);
}

- (void)domain:(PDDynamicDebuggerDomain *)domain disableWithCallback:(void (^)(id error))callback {

[WXDevToolType setDebug:NO];
[WXSDKEngine restart];
[[NSNotificationCenter defaultCenter] postNotificationName:@"RefreshInstance" object:nil];
callback(nil);
}

- (void)domain:(WXDebugDomain *)domain sendLogLevel:(NSString *)level WithCallback:(void (^)(id error))callback {
NSDictionary *logLevelMap = [WXDebugDomainController getLogLevelMap];
WXLogLevel wxLogLevel = [[logLevelMap objectForKey:level] integerValue];
[WXLog setLogLevel:wxLogLevel];
callback(nil);
}


@end

0 comments on commit 164abf8

Please sign in to comment.