Command line flags to start RN apps in web executor mode.

Reviewed By: frantic

Differential Revision: D2613142

fb-gh-sync-id: fadcea3d23825420c0412f2e4d8d51c70b0f08ed
This commit is contained in:
Natthu Bharambe
2015-11-06 14:52:43 -08:00
committed by facebook-github-bot-6
parent c4739746ba
commit cce9ba864f
2 changed files with 23 additions and 5 deletions

View File

@@ -39,7 +39,10 @@ RCT_EXPORT_MODULE()
- (instancetype)init
{
return [self initWithURL:[RCTConvert NSURL:@"http://localhost:8081/debugger-proxy"]];
NSUserDefaults *standardDefaults = [NSUserDefaults standardUserDefaults];
NSInteger port = [standardDefaults integerForKey:@"websocket-executor-port"] ?: 8081;
NSString *URLString = [NSString stringWithFormat:@"http://localhost:%zd/debugger-proxy", port];
return [self initWithURL:[RCTConvert NSURL:URLString]];
}
- (instancetype)initWithURL:(NSURL *)URL

View File

@@ -140,6 +140,8 @@ RCT_NOT_IMPLEMENTED(- (instancetype)init)
BOOL _jsLoaded;
NSArray<RCTDevMenuItem *> *_presentedItems;
NSMutableArray<RCTDevMenuItem *> *_extraMenuItems;
NSString *_webSocketExecutorName;
NSString *_executorOverride;
}
@synthesize bridge = _bridge;
@@ -189,6 +191,13 @@ RCT_EXPORT_MODULE()
[weakSelf.bridge.eventDispatcher sendDeviceEventWithName:@"toggleElementInspector" body:nil];
}]];
_webSocketExecutorName = [_defaults objectForKey:@"websocket-executor-name"] ?: @"Chrome";
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_executorOverride = [_defaults objectForKey:@"executor-override"];
});
// Delay setup until after Bridge init
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf updateSettings:_settings];
@@ -266,7 +275,7 @@ RCT_EXPORT_MODULE()
self.profilingEnabled = [_settings[@"profilingEnabled"] ?: @NO boolValue];
self.liveReloadEnabled = [_settings[@"liveReloadEnabled"] ?: @NO boolValue];
self.showFPS = [_settings[@"showFPS"] ?: @NO boolValue];
self.executorClass = NSClassFromString(_settings[@"executorClass"]);
self.executorClass = NSClassFromString(_executorOverride ?: _settings[@"executorClass"]);
}
/**
@@ -389,13 +398,18 @@ RCT_EXPORT_MODULE()
Class chromeExecutorClass = NSClassFromString(@"RCTWebSocketExecutor");
if (!chromeExecutorClass) {
[items addObject:[RCTDevMenuItem buttonItemWithTitle:@"Chrome Debugger Unavailable" handler:^{
UIAlertView *alert = RCTAlertView(@"Chrome Debugger Unavailable", @"You need to include the RCTWebSocket library to enable Chrome debugging", nil, @"OK", nil);
[items addObject:[RCTDevMenuItem buttonItemWithTitle:[NSString stringWithFormat:@"%@ Debugger Unavailable", _webSocketExecutorName] handler:^{
UIAlertView *alert = RCTAlertView(
[NSString stringWithFormat:@"%@ Debugger Unavailable", _webSocketExecutorName],
[NSString stringWithFormat:@"You need to include the RCTWebSocket library to enable %@ debugging", _webSocketExecutorName],
nil,
@"OK",
nil);
[alert show];
}]];
} else {
BOOL isDebuggingInChrome = _executorClass && _executorClass == chromeExecutorClass;
NSString *debugTitleChrome = isDebuggingInChrome ? @"Disable Chrome Debugging" : @"Debug in Chrome";
NSString *debugTitleChrome = isDebuggingInChrome ? [NSString stringWithFormat:@"Disable %@ Debugging", _webSocketExecutorName] : [NSString stringWithFormat:@"Debug in %@", _webSocketExecutorName];
[items addObject:[RCTDevMenuItem buttonItemWithTitle:debugTitleChrome handler:^{
weakSelf.executorClass = isDebuggingInChrome ? Nil : chromeExecutorClass;
}]];
@@ -527,6 +541,7 @@ RCT_EXPORT_METHOD(reload)
{
if (_executorClass != executorClass) {
_executorClass = executorClass;
_executorOverride = nil;
[self updateSetting:@"executorClass" value:NSStringFromClass(executorClass)];
}