@hot-updater/react-native 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@
9
9
  @interface HotUpdater : RCTEventEmitter <RCTBridgeModule>
10
10
  #endif // RCT_NEW_ARCH_ENABLED
11
11
 
12
+ @property (nonatomic, assign) NSTimeInterval lastUpdateTime;
12
13
  + (NSURL *)bundleURL;
13
14
 
14
15
  @end
@@ -1,11 +1,21 @@
1
1
  #import "HotUpdater.h"
2
2
  #import <React/RCTReloadCommand.h>
3
3
  #import <SSZipArchive/SSZipArchive.h>
4
+ #import <Foundation/NSURLSession.h>
4
5
 
5
6
  @implementation HotUpdater {
6
7
  bool hasListeners;
7
8
  }
8
9
 
10
+
11
+ - (instancetype)init {
12
+ self = [super init];
13
+ if (self) {
14
+ _lastUpdateTime = 0;
15
+ }
16
+ return self;
17
+ }
18
+
9
19
  RCT_EXPORT_MODULE();
10
20
 
11
21
  #pragma mark - Bundle URL Management
@@ -153,22 +163,44 @@ RCT_EXPORT_MODULE();
153
163
  }
154
164
  }];
155
165
 
156
-
166
+
157
167
  // Add observer for progress updates
158
168
  [downloadTask addObserver:self
159
- forKeyPath:@"countOfBytesReceived"
160
- options:NSKeyValueObservingOptionNew
161
- context:nil];
169
+ forKeyPath:@"countOfBytesReceived"
170
+ options:NSKeyValueObservingOptionNew
171
+ context:nil];
162
172
  [downloadTask addObserver:self
163
- forKeyPath:@"countOfBytesExpectedToReceive"
164
- options:NSKeyValueObservingOptionNew
165
- context:nil];
166
-
173
+ forKeyPath:@"countOfBytesExpectedToReceive"
174
+ options:NSKeyValueObservingOptionNew
175
+ context:nil];
176
+
177
+ __block HotUpdater *weakSelf = self;
178
+ [[NSNotificationCenter defaultCenter] addObserverForName:@"NSURLSessionDownloadTaskDidFinishDownloading"
179
+ object:downloadTask
180
+ queue:[NSOperationQueue mainQueue]
181
+ usingBlock:^(NSNotification * _Nonnull note) {
182
+ [weakSelf removeObserversForTask:downloadTask];
183
+ }];
167
184
  [downloadTask resume];
185
+
168
186
  }
169
187
 
170
188
  #pragma mark - Progress Updates
171
189
 
190
+
191
+ - (void)removeObserversForTask:(NSURLSessionDownloadTask *)task {
192
+ @try {
193
+ if ([task observationInfo]) {
194
+ [task removeObserver:self forKeyPath:@"countOfBytesReceived"];
195
+ [task removeObserver:self forKeyPath:@"countOfBytesExpectedToReceive"];
196
+ NSLog(@"KVO observers removed successfully for task: %@", task);
197
+ }
198
+ } @catch (NSException *exception) {
199
+ NSLog(@"Failed to remove observers: %@", exception);
200
+ }
201
+ }
202
+
203
+
172
204
  - (void)observeValueForKeyPath:(NSString *)keyPath
173
205
  ofObject:(id)object
174
206
  change:(NSDictionary<NSKeyValueChangeKey, id> *)change
@@ -179,8 +211,16 @@ RCT_EXPORT_MODULE();
179
211
  if (task.countOfBytesExpectedToReceive > 0) {
180
212
  double progress = (double)task.countOfBytesReceived / (double)task.countOfBytesExpectedToReceive;
181
213
 
182
- // Send progress to React Native
183
- [self sendEventWithName:@"onProgress" body:@{@"progress": @(progress)}];
214
+ // Get current timestamp
215
+ NSTimeInterval currentTime = [[NSDate date] timeIntervalSince1970] * 1000; // Convert to milliseconds
216
+
217
+ // Send event only if 100ms has passed OR progress is 100%
218
+ if ((currentTime - self.lastUpdateTime) >= 100 || progress >= 1.0) {
219
+ self.lastUpdateTime = currentTime; // Update last event timestamp
220
+
221
+ // Send progress to React Native
222
+ [self sendEventWithName:@"onProgress" body:@{@"progress": @(progress)}];
223
+ }
184
224
  }
185
225
  }
186
226
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hot-updater/react-native",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "React Native OTA solution for self-hosted",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -78,8 +78,8 @@
78
78
  "react-native-builder-bob": "^0.33.1"
79
79
  },
80
80
  "dependencies": {
81
- "@hot-updater/js": "0.8.0",
82
- "@hot-updater/core": "0.8.0"
81
+ "@hot-updater/js": "0.9.0",
82
+ "@hot-updater/core": "0.9.0"
83
83
  },
84
84
  "scripts": {
85
85
  "build": "rslib build",