1// Copyright 2020-present 650 Industries. All rights reserved.
2
3#if __has_include(<EXUpdates/EXUpdatesService.h>)
4
5#import "EXUpdatesBinding.h"
6
7NS_ASSUME_NONNULL_BEGIN
8
9@interface EXUpdatesBinding ()
10
11@property (nonatomic, strong) NSString *scopeKey;
12@property (nonatomic, weak) id<EXUpdatesBindingDelegate> updatesKernelService;
13@property (nonatomic, weak) id<EXUpdatesDatabaseBindingDelegate> databaseKernelService;
14
15@end
16
17/**
18 * Scoped internal module which overrides EXUpdatesService at runtime in Expo Go, and gives
19 * EXUpdatesModule access to properties from the correct instance of EXAppLoaderExpoUpdates (through
20 * EXUpdatesKernelService) as well as the global database object (through
21 * EXUpdatesDatabaseKernelService).
22 */
23@implementation EXUpdatesBinding : EXUpdatesService
24
25- (instancetype)initWithScopeKey:(NSString *)scopeKey updatesKernelService:(id<EXUpdatesBindingDelegate>)updatesKernelService databaseKernelService:(id<EXUpdatesDatabaseBindingDelegate>)databaseKernelService
26{
27  if (self = [super init]) {
28    _scopeKey = scopeKey;
29    _updatesKernelService = updatesKernelService;
30    _databaseKernelService = databaseKernelService;
31  }
32  return self;
33}
34
35- (nullable EXUpdatesConfig *)config
36{
37  return [_updatesKernelService configForScopeKey:_scopeKey];
38}
39
40- (EXUpdatesDatabase *)database
41{
42  return _databaseKernelService.database;
43}
44
45- (nullable EXUpdatesSelectionPolicy *)selectionPolicy
46{
47  return [_updatesKernelService selectionPolicyForScopeKey:_scopeKey];
48}
49
50- (NSURL *)directory
51{
52  return _databaseKernelService.updatesDirectory;
53}
54
55- (nullable EXUpdatesUpdate *)embeddedUpdate
56{
57  return nil;
58}
59
60- (nullable EXUpdatesUpdate *)launchedUpdate
61{
62  return [_updatesKernelService launchedUpdateForScopeKey:_scopeKey];
63}
64
65- (nullable NSDictionary *)assetFilesMap
66{
67  return [_updatesKernelService assetFilesMapForScopeKey:_scopeKey];
68}
69
70- (BOOL)isUsingEmbeddedAssets
71{
72  return [_updatesKernelService isUsingEmbeddedAssetsForScopeKey:_scopeKey];
73}
74
75- (BOOL)isStarted
76{
77  return [_updatesKernelService isStartedForScopeKey:_scopeKey];
78}
79
80- (BOOL)isEmergencyLaunch
81{
82  return [_updatesKernelService isEmergencyLaunchForScopeKey:_scopeKey];
83}
84
85- (BOOL)canRelaunch
86{
87  return YES;
88}
89
90- (void)requestRelaunchWithCompletion:(EXUpdatesAppRelaunchCompletionBlock)completion
91{
92  return [_updatesKernelService requestRelaunchForScopeKey:_scopeKey withCompletion:completion];
93}
94
95- (void)resetSelectionPolicy
96{
97  // no-op in managed
98}
99
100+ (const NSArray<Protocol *> *)exportedInterfaces {
101  return @[@protocol(EXUpdatesModuleInterface)];
102}
103
104@end
105
106NS_ASSUME_NONNULL_END
107
108#endif
109