From 91b7499cf68a349f45e5480f987e4a7d1fdc3aa4 Mon Sep 17 00:00:00 2001 From: Mehdi Mulani Date: Fri, 13 Jan 2017 12:26:23 -0800 Subject: [PATCH] Expose environment and arguments to JS Summary: Right now from JS there's no way to see the environment variables or arguments that the application was started with. The main use case for this is to help enable/disable features when being run in a testing environment (as environment variables are the easiest way to communicate). javache is it okay to reference these constants from JS at startup time? I am planning to disable yellow boxes via an environment variable. achen1 how easy is it expose these two things for Android as well? Reviewed By: achen1 Differential Revision: D4395091 fbshipit-source-id: fc318e6a60b8829f7eb4491ea8f3258f68f59c8c --- React/Modules/RCTProcessInfo.h | 15 +++++++++++++++ React/Modules/RCTProcessInfo.m | 26 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 React/Modules/RCTProcessInfo.h create mode 100644 React/Modules/RCTProcessInfo.m diff --git a/React/Modules/RCTProcessInfo.h b/React/Modules/RCTProcessInfo.h new file mode 100644 index 00000000000..f4a501fbeee --- /dev/null +++ b/React/Modules/RCTProcessInfo.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import +#import + +@interface RCTProcessInfo : NSObject + +@end diff --git a/React/Modules/RCTProcessInfo.m b/React/Modules/RCTProcessInfo.m new file mode 100644 index 00000000000..bd15c2cf2c6 --- /dev/null +++ b/React/Modules/RCTProcessInfo.m @@ -0,0 +1,26 @@ +/** + * Copyright (c) 2017-present, Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD-style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + */ + +#import "RCTProcessInfo.h" + +@implementation RCTProcessInfo + +RCT_EXPORT_MODULE() + +- (NSDictionary *)constantsToExport +{ + NSProcessInfo *processInfo = [NSProcessInfo processInfo]; + return + @{ + @"environment": processInfo.environment, + @"arguments": processInfo.arguments, + }; +} + +@end