Skip to content

Commit

Permalink
Add support for os.homedir()
Browse files Browse the repository at this point in the history
Android will use APK dataDir.
iOS will use DocumentDirectory.
  • Loading branch information
staltz authored and phillbaker committed Mar 31, 2018
1 parent 1d8475b commit 8dfb18b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions android/src/main/java/com/peel/react/RNOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public Map<String, Object> getConstants() {
}

constants.put("networkInterfaces", networkMap);
constants.put("homedir", getReactApplicationContext().getApplicationInfo().dataDir);
return constants;
}

Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ exports.tmpdir = exports.tmpDir = function () {
return '/tmp';
};

exports.homedir = function () {
return RNOS.homedir;
};

exports.EOL = '\n';
11 changes: 10 additions & 1 deletion ios/RNOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8dfb18b

Please sign in to comment.