1// Copyright 2020-present 650 Industries. All rights reserved.
2
3#import <EXUpdates/EXUpdatesService.h>
4#import <ExpoModulesCore/EXUtilities.h>
5
6#if __has_include(<EXUpdates/EXUpdates-Swift.h>)
7#import <EXUpdates/EXUpdates-Swift.h>
8#else
9#import "EXUpdates-Swift.h"
10#endif
11
12NS_ASSUME_NONNULL_BEGIN
13
14/**
15 * Internal module whose purpose is to connect EXUpdatesModule with the central updates entry point.
16 * In most apps, this is EXUpdatesAppController.
17 *
18 * In other cases, this module can be overridden at runtime to redirect EXUpdatesModule to a
19 * different entry point. This is the case in Expo Go, where this module is overridden by
20 * EXUpdatesBinding in order to get data from EXAppLoaderExpoUpdates.
21 */
22@implementation EXUpdatesService
23
24EX_REGISTER_MODULE();
25
26+ (const NSArray<Protocol *> *)exportedInterfaces
27{
28#if SUPPRESS_EXPO_UPDATES_SERVICE // used in Expo Go
29  return @[];
30#endif
31  return @[@protocol(EXUpdatesModuleInterface)];
32}
33
34- (nullable EXUpdatesConfig *)config
35{
36#if SUPPRESS_EXPO_UPDATES_SERVICE // used in Expo Go
37  return nil;
38#endif
39  return EXUpdatesAppController.sharedInstance.config;
40}
41
42- (EXUpdatesDatabase *)database
43{
44  return EXUpdatesAppController.sharedInstance.database;
45}
46
47- (nullable EXUpdatesSelectionPolicy *)selectionPolicy
48{
49  return EXUpdatesAppController.sharedInstance.selectionPolicy;
50}
51
52- (NSURL *)directory
53{
54  return EXUpdatesAppController.sharedInstance.updatesDirectory;
55}
56
57- (nullable EXUpdatesUpdate *)embeddedUpdate
58{
59  return [EXUpdatesEmbeddedAppLoader embeddedManifestWithConfig:self.config database:self.database];
60}
61
62- (nullable EXUpdatesUpdate *)launchedUpdate
63{
64  return EXUpdatesAppController.sharedInstance.launchedUpdate;
65}
66
67- (nullable NSDictionary *)assetFilesMap
68{
69  return EXUpdatesAppController.sharedInstance.assetFilesMap;
70}
71
72- (BOOL)isUsingEmbeddedAssets
73{
74  return EXUpdatesAppController.sharedInstance.isUsingEmbeddedAssets;
75}
76
77- (BOOL)isEmbeddedLaunch
78{
79  // True if the embedded update and its ID are not nil, and match
80  // the ID of the launched update
81  return [[self embeddedUpdate] updateId] != nil &&
82  [[[self embeddedUpdate] updateId] isEqual:[[self launchedUpdate] updateId]];
83}
84
85- (BOOL)isStarted
86{
87  return EXUpdatesAppController.sharedInstance.isStarted;
88}
89
90- (BOOL)isEmergencyLaunch
91{
92  return EXUpdatesAppController.sharedInstance.isEmergencyLaunch;
93}
94
95- (BOOL)canRelaunch
96{
97  return EXUpdatesAppController.sharedInstance.isStarted;
98}
99
100- (BOOL)canCheckForUpdateAndFetchUpdate
101{
102  return YES;
103}
104
105- (void)requestRelaunchWithCompletion:(EXUpdatesAppRelaunchCompletionBlock)completion
106{
107  return [EXUpdatesAppController.sharedInstance requestRelaunchWithCompletion:completion];
108}
109
110- (void)resetSelectionPolicy
111{
112  return [EXUpdatesAppController.sharedInstance resetSelectionPolicyToDefault];
113}
114
115@end
116
117NS_ASSUME_NONNULL_END
118