1// Copyright 2015-present 650 Industries. All rights reserved.
2
3#import "EXFrame.h"
4#import "EXFrameReactAppManager.h"
5#import "EXKernelAppRecord.h"
6
7#import <React/RCTUtils.h>
8
9NSString *kEXKernelBridgeDidForegroundNotification = @"EXKernelBridgeDidForegroundNotification";
10NSString *kEXKernelBridgeDidBackgroundNotification = @"EXKernelBridgeDidBackgroundNotification";
11
12@implementation EXKernelAppRecord
13
14+ (instancetype)recordWithManifestUrl:(NSURL *)manifestUrl
15{
16  return [[EXKernelAppRecord alloc] initWithManifestUrl:manifestUrl];
17}
18
19- (instancetype)initWithManifestUrl:(NSURL *)manifestUrl
20{
21  if (self = [super init]) {
22    _manifestUrl = manifestUrl;
23    _appLoader = [[EXKernelAppLoader alloc] initWithManifestUrl:manifestUrl];
24    _timeCreated = [NSDate date];
25    _experienceFinishedLoading = NO;
26  }
27  return self;
28}
29
30- (EXKernelAppRecordStatus)status
31{
32  if (self.experienceFinishedLoading) {
33    return EXKernelAppRecordStatusRunning;
34  }
35  if (self.appLoader.bundleFinished) {
36    return EXKernelAppRecordStatusHasManifestAndBundle;
37  }
38  if (self.appLoader.manifest) {
39    return EXKernelAppRecordStatusHasManifest;
40  }
41  return EXKernelAppRecordStatusNew;
42}
43
44- (NSString * _Nullable)experienceId
45{
46  if (self.appLoader && self.appLoader.manifest) {
47    id experienceIdJsonValue = self.appLoader.manifest[@"id"];
48    if (experienceIdJsonValue) {
49      RCTAssert([experienceIdJsonValue isKindOfClass:[NSString class]], @"Manifest contains an id which is not a string: %@", experienceIdJsonValue);
50      return experienceIdJsonValue;
51    }
52  }
53  return nil;
54}
55
56@end
57
58