1// Copyright 2015-present 650 Industries. All rights reserved.
2#import "EXDevMenuAppInfo.h"
3
4@implementation EXDevMenuAppInfo
5
6// TODO -- EXManifest - use actual interface
7//- (nullable NSString *)sdkVersion;
8//- (NSString *)bundleUrl;
9//- (nullable NSString *)revisionId;
10//- (nullable NSString *)slug;
11//- (nullable NSString *)appKey;
12//- (nullable NSString *)name;
13//- (nullable NSString *)version;
14//- (nullable NSDictionary *)notificationPreferences;
15//- (nullable NSDictionary *)updatesInfo;
16//- (nullable NSDictionary *)iosConfig;
17//- (nullable NSString *)hostUri;
18//- (nullable NSString *)orientation;
19//- (nullable NSDictionary *)experiments;
20//- (nullable NSDictionary *)developer;
21//- (nullable NSString *)facebookAppId;
22//- (nullable NSString *)facebookApplicationName;
23//- (BOOL)facebookAutoInitEnabled;
24
25+(NSDictionary *)getAppInfoForBridge:(RCTBridge *)bridge andManifest:(NSDictionary *)manifest
26{
27  NSMutableDictionary *appInfo = [NSMutableDictionary new];
28
29  NSString *appIcon = [EXDevMenuAppInfo getAppIcon];
30  NSString *runtimeVersion = [EXDevMenuAppInfo getUpdatesConfigForKey:@"EXUpdatesRuntimeVersion"];
31  NSString *sdkVersion = [EXDevMenuAppInfo getUpdatesConfigForKey:@"EXUpdatesSDKVersion"];
32  NSString *appVersion = [EXDevMenuAppInfo getFormattedAppVersion];
33  NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleDisplayName"] ?: [[NSBundle mainBundle] objectForInfoDictionaryKey: @"CFBundleExecutable"];
34  NSString *hostUrl = [bridge.bundleURL host] ?: @"";
35
36  if (manifest[@"name"] != nil) {
37    appName = manifest[@"name"];
38  }
39
40  if (manifest[@"version"] != nil) {
41    appVersion = manifest[@"version"];
42  }
43
44  appInfo[@"appName"] = appName;
45  appInfo[@"appIcon"] = appIcon;
46  appInfo[@"appVersion"] = appVersion;
47  appInfo[@"runtimeVersion"] = runtimeVersion;
48  appInfo[@"sdkVersion"] = sdkVersion;
49  appInfo[@"hostUrl"] = hostUrl;
50
51  return appInfo;
52}
53
54+(NSString *)getAppIcon
55{
56  NSString *appIcon = @"";
57  NSString *appIconName = [[[[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIcons"] objectForKey:@"CFBundlePrimaryIcon"] objectForKey:@"CFBundleIconFiles"]  lastObject];
58
59  if (appIconName != nil) {
60    NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
61    NSString *appIconPath = [[resourcePath stringByAppendingString:appIconName] stringByAppendingString:@".png"];
62    appIcon = [@"file://" stringByAppendingString:appIconPath];
63  }
64
65  return appIcon;
66}
67
68+(NSString *)getUpdatesConfigForKey:(NSString *)key
69{
70  NSString *value = @"";
71  NSString *path = [[NSBundle mainBundle] pathForResource:@"Expo" ofType:@"plist"];
72
73  if (path != nil) {
74    NSDictionary *expoConfig = [NSDictionary dictionaryWithContentsOfFile:path];
75
76    if (expoConfig != nil) {
77      value = [expoConfig objectForKey:key] ?: @"";
78    }
79  }
80
81  return value;
82}
83
84+(NSString *)getFormattedAppVersion
85{
86  NSString *shortVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
87  NSString *buildVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
88  NSString *appVersion = [NSString stringWithFormat:@"%@ (%@)", shortVersion, buildVersion];
89  return appVersion;
90}
91
92@end
93