1 // Copyright 2015-present 650 Industries. All rights reserved.
2 
3 #import <Foundation/Foundation.h>
4 #import "EXResourceLoader.h"
5 
6 @class EXAppLoader;
7 @class EXAppFetcher;
8 
9 NS_ASSUME_NONNULL_BEGIN
10 
11 @protocol EXAppFetcherDelegate <NSObject>
12 
13 /**
14  *  If the delegate guessed incorrectly about which subclass of AppFetcher to use,
15  *  this method should be called so that the new AppFetcher can be set up properly.
16  *
17  *  Use retainingCurrent:YES only if the current (calling) AppFetcher is still doing work
18  *  (e.g. fetching an update in the background) and should not be immediately deallocated.
19  */
20 - (void)appFetcher:(EXAppFetcher *)appFetcher didSwitchToAppFetcher:(EXAppFetcher *)newAppFetcher retainingCurrent:(BOOL)shouldRetain;
21 
22 - (void)appFetcher:(EXAppFetcher *)appFetcher didLoadOptimisticManifest:(NSDictionary *)manifest;
23 - (void)appFetcher:(EXAppFetcher *)appFetcher didFinishLoadingManifest:(NSDictionary *)manifest bundle:(NSData *)bundle;
24 - (void)appFetcher:(EXAppFetcher *)appFetcher didFailWithError:(NSError *)error;
25 
26 @end
27 
28 @protocol EXAppFetcherDataSource <NSObject>
29 
30 - (NSString *)bundleResourceNameForAppFetcher:(EXAppFetcher *)appFetcher withManifest:(NSDictionary *)manifest;
31 - (BOOL)appFetcherShouldInvalidateBundleCache:(EXAppFetcher *)appFetcher;
32 
33 @end
34 
35 @protocol EXAppFetcherCacheDataSource <NSObject>
36 
37 - (BOOL)isCacheUpToDateWithAppFetcher:(EXAppFetcher *)appFetcher;
38 
39 @end
40 
41 @interface EXAppFetcher : NSObject
42 
43 @property (nonatomic, readonly) NSDictionary * _Nullable manifest;
44 @property (nonatomic, readonly) NSData * _Nullable bundle;
45 @property (nonatomic, readonly) NSError * _Nullable error;
46 
47 @property (nonatomic, weak) id<EXAppFetcherDelegate> delegate;
48 @property (nonatomic, weak) id<EXAppFetcherDataSource> dataSource;
49 @property (nonatomic, weak) id<EXAppFetcherCacheDataSource> cacheDataSource;
50 
51 - (instancetype)initWithAppLoader:(EXAppLoader *)appLoader;
52 - (void)start;
53 
54 - (void)fetchJSBundleWithManifest:(NSDictionary *)manifest
55                     cacheBehavior:(EXCachedResourceBehavior)cacheBehavior
56                   timeoutInterval:(NSTimeInterval)timeoutInterval
57                          progress:(void (^ _Nullable )(EXLoadingProgress *))progressBlock
58                           success:(void (^)(NSData *))successBlock
59                             error:(void (^)(NSError *))errorBlock;
60 
61 + (NSString *)experienceIdWithManifest:(NSDictionary *)manifest;
62 + (BOOL)areDevToolsEnabledWithManifest:(NSDictionary *)manifest;
63 + (EXCachedResourceBehavior)cacheBehaviorForJSWithManifest:(NSDictionary *)manifest;
64 
65 @end
66 
67 NS_ASSUME_NONNULL_END
68