From 8dfb18bbaa3abfa0f2d9b96a79636abf45edf473 Mon Sep 17 00:00:00 2001 From: Andre Staltz Date: Thu, 16 Nov 2017 18:12:05 +0200 Subject: [PATCH] Add support for os.homedir() Android will use APK dataDir. iOS will use DocumentDirectory. --- android/src/main/java/com/peel/react/RNOS.java | 1 + index.js | 4 ++++ ios/RNOS.m | 11 ++++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/peel/react/RNOS.java b/android/src/main/java/com/peel/react/RNOS.java index f705984..245251e 100644 --- a/android/src/main/java/com/peel/react/RNOS.java +++ b/android/src/main/java/com/peel/react/RNOS.java @@ -67,6 +67,7 @@ public Map getConstants() { } constants.put("networkInterfaces", networkMap); + constants.put("homedir", getReactApplicationContext().getApplicationInfo().dataDir); return constants; } diff --git a/index.js b/index.js index eafec76..1eea77d 100644 --- a/index.js +++ b/index.js @@ -58,4 +58,8 @@ exports.tmpdir = exports.tmpDir = function () { return '/tmp'; }; +exports.homedir = function () { + return RNOS.homedir; +}; + exports.EOL = '\n'; diff --git a/ios/RNOS.m b/ios/RNOS.m index d9a79b3..098e02e 100644 --- a/ios/RNOS.m +++ b/ios/RNOS.m @@ -63,10 +63,19 @@ - (void)invalidate [self stopObserving]; } +- (NSString *)getPathForDirectory:(int)directory +{ + NSArray *paths = NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, YES); + return [paths firstObject]; +} + - (NSDictionary *)constantsToExport { // initialize os info dict - return @{@"networkInterfaces": [self networkInterfaces]}; + return @{ + @"networkInterfaces": [self networkInterfaces], + @"homedir": [self getPathForDirectory:NSDocumentDirectory] + }; } - (NSDictionary*)networkInterfaces {