react-native-ota-hot-update 1.0.4 → 1.0.6

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.
@@ -75,13 +75,13 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
75
75
  @ReactMethod
76
76
  public void setupBundlePath(String path, Promise promise) {
77
77
  if (path != null) {
78
+ deleteOldBundleIfneeded();
78
79
  File file = new File(path);
79
80
  if (file.exists() && file.isFile()) {
80
81
  String fileUnzip = unzip(file);
81
82
  Log.d("setupBundlePath: ", fileUnzip);
82
83
  if (fileUnzip != null) {
83
84
  file.delete();
84
- deleteOldBundleIfneeded();
85
85
  SharedPrefs sharedPrefs = new SharedPrefs(getReactApplicationContext());
86
86
  sharedPrefs.putString(Common.INSTANCE.getPATH(), fileUnzip);
87
87
  promise.resolve(true);
package/ios/RNhotupdate.m CHANGED
@@ -98,11 +98,11 @@ RCT_EXPORT_MODULE()
98
98
  // Expose setupBundlePath method to JavaScript
99
99
  RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) {
100
100
  if ([self isFilePathValid:path]) {
101
+ [self removeBundleIfNeeded];
101
102
  //Unzip file
102
103
  NSString *extractedFilePath = [self unzipFileAtPath:path];
103
104
  NSLog(@"file extraction----- %@", extractedFilePath);
104
105
  if (extractedFilePath) {
105
- [self removeBundleIfNeeded];
106
106
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
107
107
  [defaults setObject:extractedFilePath forKey:@"PATH"];
108
108
  [defaults synchronize];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "Hot update for react native",
5
5
  "main": "src/index",
6
6
  "repository": "https://github.com/vantuan88291/react-native-ota-hot-update",
package/src/index.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import { NativeModules, Platform } from 'react-native';
2
- import {downloadBundleFile} from './Utils.ts';
2
+ import ReactNativeBlobUtil from 'react-native-blob-util';
3
3
  const LINKING_ERROR =
4
4
  'The package \'rn-hotupdate\' doesn\'t seem to be linked. Make sure: \n\n' +
5
5
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
@@ -23,7 +23,21 @@ const RNhotupdate = NativeModules.RNhotupdate
23
23
  },
24
24
  }
25
25
  );
26
-
26
+ const downloadBundleFile = async (uri: string, headers?: object, callback?: (received: string, total: string) => void) => {
27
+ const res = await ReactNativeBlobUtil
28
+ .config({
29
+ fileCache: Platform.OS === 'android',
30
+ })
31
+ .fetch('GET', uri, {
32
+ ...headers,
33
+ })
34
+ .progress((received, total) => {
35
+ if (callback) {
36
+ callback(received, total)
37
+ }
38
+ });
39
+ return res.path();
40
+ };
27
41
  function setupBundlePath(path: string): Promise<boolean> {
28
42
  return RNhotupdate.setupBundlePath(path);
29
43
  }
package/src/Utils.ts DELETED
@@ -1,19 +0,0 @@
1
- import {
2
- Platform,
3
- } from 'react-native';
4
- import ReactNativeBlobUtil from 'react-native-blob-util';
5
- export const downloadBundleFile = async (uri: string, headers?: object, callback?: (received: string, total: string) => void) => {
6
- const res = await ReactNativeBlobUtil
7
- .config({
8
- fileCache: Platform.OS === 'android',
9
- })
10
- .fetch('GET', uri, {
11
- ...headers,
12
- })
13
- .progress((received, total) => {
14
- if (callback) {
15
- callback(received, total)
16
- }
17
- });
18
- return res.path();
19
- };