react-native-ota-hot-update 2.2.72 → 2.3.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.
package/README.md CHANGED
@@ -69,18 +69,13 @@ Open `AppDelegate.m` and add this:
69
69
 
70
70
  From react native 0.77, AppDelegate changed to swift file, so the configuration will be change a bit.
71
71
 
72
- 1. Create a Bridging Header
73
- - Right-click on your project in the Xcode navigator and select New File from template.
74
- - Select Header File under the iOS section and click Next.
75
- - Name it something like `YourProjectName-Bridging-Header.h` and save it in your project directory.
76
- - In your project's Build Settings: Search for `Objective-C Bridging Header`.
77
- Set its value to the relative path of your bridging header file, e.g., YourProjectName/YourProjectName-Bridging-Header.h, remember need to create header file inside folder `YourProjectName`
78
- 2. Open `YourProjectName-Bridging-Header.h` and add this line:
79
-
80
- `#import "OtaHotUpdate.h"`
81
- 3. Open AppDelegate.swift:
72
+ Open AppDelegate.swift:
82
73
 
83
74
  ```bash
75
+
76
+ import react_native_ota_hot_update
77
+ ...
78
+
84
79
  override func bundleURL() -> URL? {
85
80
  #if DEBUG
86
81
  RCTBundleURLProvider.sharedSettings().jsBundleURL(forBundleRoot: "index")
@@ -164,6 +159,13 @@ MainApplication.java:
164
159
 
165
160
  For java it maybe can be like: `OtaHotUpdate.Companion.getBundleJS(this)` depend on kotlin / jdk version on your project, you can use android studio to get the correct format coding.
166
161
 
162
+ If want to remove bundle wrong handler, pass false param in getBundleJS like this:
163
+
164
+ ```aiignore
165
+ return OtaHotUpdate.bundleJS(this@MainApplication, false)
166
+
167
+ ```
168
+
167
169
  Open `AndroidManifest.xml` :
168
170
 
169
171
  `<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />`
@@ -1,14 +1,10 @@
1
1
  package com.otahotupdate
2
2
 
3
3
  import android.content.Context
4
- import android.os.Handler
5
- import android.os.Looper
6
4
  import android.widget.Toast
7
- import androidx.appcompat.app.AlertDialog
8
5
  import com.jakewharton.processphoenix.ProcessPhoenix
9
6
  import com.rnhotupdate.Common.PATH
10
7
  import com.rnhotupdate.Common.PREVIOUS_PATH
11
- import com.rnhotupdate.Common.VERSION
12
8
  import com.rnhotupdate.SharedPrefs
13
9
  import kotlinx.coroutines.Dispatchers
14
10
  import kotlinx.coroutines.GlobalScope
@@ -41,7 +37,8 @@ class CrashHandler(private val context: Context) : Thread.UncaughtExceptionHandl
41
37
  } else {
42
38
  sharedPrefs.putString(PATH, "")
43
39
  }
44
- Toast.makeText(context, "Failed to load the update. Please try again.", Toast.LENGTH_LONG).show()
40
+ val errorMessage = throwable.message ?: "Unknown error occurred"
41
+ Toast.makeText(context, "Update failed: $errorMessage", Toast.LENGTH_LONG).show()
45
42
  GlobalScope.launch(Dispatchers.IO) {
46
43
  delay(1500)
47
44
  ProcessPhoenix.triggerRebirth(context)
@@ -59,8 +59,10 @@ class OtaHotUpdate : TurboReactPackage() {
59
59
  }
60
60
  }
61
61
  }
62
- fun bundleJS(context: Context): String {
63
- Thread.setDefaultUncaughtExceptionHandler(CrashHandler(context))
62
+ fun bundleJS(context: Context, isHandleCrash: Boolean = true): String {
63
+ if (isHandleCrash) {
64
+ Thread.setDefaultUncaughtExceptionHandler(CrashHandler(context))
65
+ }
64
66
  val sharedPrefs = SharedPrefs(context)
65
67
  val pathBundle = sharedPrefs.getString(PATH)
66
68
  val version = sharedPrefs.getString(VERSION)
@@ -1,13 +1,13 @@
1
1
  #import <React/RCTReloadCommand.h>
2
- #ifdef RCT_NEW_ARCH_ENABLED
3
- #import "RNOtaHotUpdateSpec.h"
4
2
 
3
+ #if defined(RCT_NEW_ARCH_ENABLED) && __has_include("RNOtaHotUpdateSpec.h")
4
+ #import "RNOtaHotUpdateSpec.h"
5
5
  @interface OtaHotUpdate : NSObject <NativeOtaHotUpdateSpec>
6
6
  #else
7
7
  #import <React/RCTBridgeModule.h>
8
-
9
8
  @interface OtaHotUpdate : NSObject <RCTBridgeModule>
10
9
  #endif
10
+
11
11
  + (NSURL *)getBundle;
12
12
 
13
13
  @end
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ota-hot-update",
3
- "version": "2.2.72",
3
+ "version": "2.3.0",
4
4
  "description": "Hot update for react native",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/commonjs/index.js",
@@ -19,11 +19,25 @@ import com.otahotupdate.OtaHotUpdate`);
19
19
  };
20
20
  const withIosAction = (config) => {
21
21
  return (0, config_plugins_1.withAppDelegate)(config, (config) => {
22
- if (!config.modResults.contents.includes('#import "OtaHotUpdate.h')) {
23
- config.modResults.contents = config.modResults.contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"
22
+ const appDelegatePath = config.modRequest.projectRoot + '/ios/' + config_plugins_1.IOSConfig.Paths.getAppDelegateFilePath(config.modRequest.projectRoot);
23
+ const isSwift = appDelegatePath.endsWith('.swift');
24
+ if (isSwift) {
25
+ // Swift: AppDelegate.swift
26
+ if (!config.modResults.contents.includes('import react_native_ota_hot_update')) {
27
+ config.modResults.contents = `import react_native_ota_hot_update\n${config.modResults.contents}`;
28
+ }
29
+ if (!config.modResults.contents.includes('OtaHotUpdate.getBundle()')) {
30
+ config.modResults.contents = config.modResults.contents.replace(/return Bundle.main.url\(forResource: "main", withExtension: "jsbundle"\)/, `return OtaHotUpdate.getBundle()`);
31
+ }
32
+ }
33
+ else {
34
+ // Objective-C: AppDelegate.mm
35
+ if (!config.modResults.contents.includes('#import "OtaHotUpdate.h')) {
36
+ config.modResults.contents = config.modResults.contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"
24
37
  #import "OtaHotUpdate.h"`);
38
+ }
39
+ config.modResults.contents = config.modResults.contents.replace(/\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/, `[OtaHotUpdate getBundle]`);
25
40
  }
26
- config.modResults.contents = config.modResults.contents.replace(/\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/, `[OtaHotUpdate getBundle]`);
27
41
  return config;
28
42
  });
29
43
  };
@@ -1,4 +1,9 @@
1
- import { withMainApplication, withAppDelegate } from '@expo/config-plugins';
1
+ import {
2
+ withMainApplication,
3
+ withAppDelegate,
4
+ IOSConfig,
5
+ } from '@expo/config-plugins';
6
+
2
7
  const withAndroidAction: any = (config: any) => {
3
8
  return withMainApplication(config, (config) => {
4
9
  if (!config.modResults.contents.includes('override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)')) {
@@ -25,18 +30,37 @@ import com.otahotupdate.OtaHotUpdate`
25
30
 
26
31
  const withIosAction: any = (config: any) => {
27
32
  return withAppDelegate(config, (config) => {
28
- if (!config.modResults.contents.includes('#import "OtaHotUpdate.h')) {
29
- config.modResults.contents = config.modResults.contents.replace(
30
- /#import "AppDelegate.h"/g,
31
- `#import "AppDelegate.h"
33
+ const appDelegatePath = config.modRequest.projectRoot + '/ios/' + IOSConfig.Paths.getAppDelegateFilePath(config.modRequest.projectRoot);
34
+ const isSwift = appDelegatePath.endsWith('.swift');
35
+
36
+ if (isSwift) {
37
+ // Swift: AppDelegate.swift
38
+ if (!config.modResults.contents.includes('import react_native_ota_hot_update')) {
39
+ config.modResults.contents = `import react_native_ota_hot_update\n${config.modResults.contents}`;
40
+ }
41
+
42
+ if (!config.modResults.contents.includes('OtaHotUpdate.getBundle()')) {
43
+ config.modResults.contents = config.modResults.contents.replace(
44
+ /return Bundle.main.url\(forResource: "main", withExtension: "jsbundle"\)/,
45
+ `return OtaHotUpdate.getBundle()`
46
+ );
47
+ }
48
+ } else {
49
+ // Objective-C: AppDelegate.mm
50
+ if (!config.modResults.contents.includes('#import "OtaHotUpdate.h')) {
51
+ config.modResults.contents = config.modResults.contents.replace(
52
+ /#import "AppDelegate.h"/g,
53
+ `#import "AppDelegate.h"
32
54
  #import "OtaHotUpdate.h"`
55
+ );
56
+ }
57
+
58
+ config.modResults.contents = config.modResults.contents.replace(
59
+ /\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/,
60
+ `[OtaHotUpdate getBundle]`
33
61
  );
34
62
  }
35
63
 
36
- config.modResults.contents = config.modResults.contents.replace(
37
- /\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/,
38
- `[OtaHotUpdate getBundle]`
39
- );
40
64
  return config;
41
65
  });
42
66
  };
@@ -46,4 +70,5 @@ const withAction: any = (config: any) => {
46
70
  config = withIosAction(config);
47
71
  return config;
48
72
  };
73
+
49
74
  module.exports = withAction;