react-native-ota-hot-update 2.2.2 → 2.2.4
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/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +19 -10
- package/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +6 -6
- package/android/src/main/java/com/otahotupdate/SharedPrefs.kt +1 -1
- package/ios/OtaHotUpdate.mm +3 -0
- package/package.json +1 -1
- package/plugin/build/index.js +9 -3
- package/plugin/src/index.ts +20 -12
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
package com.otahotupdate
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import android.content.pm.PackageInfo
|
|
5
4
|
import android.content.pm.PackageManager
|
|
6
5
|
import android.os.Build
|
|
7
6
|
import com.facebook.react.BaseReactPackage
|
|
@@ -9,7 +8,7 @@ import com.facebook.react.bridge.NativeModule
|
|
|
9
8
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
10
9
|
import com.facebook.react.module.model.ReactModuleInfo
|
|
11
10
|
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
12
|
-
import com.rnhotupdate.Common.
|
|
11
|
+
import com.rnhotupdate.Common.CURRENT_VERSION_CODE
|
|
13
12
|
import com.rnhotupdate.Common.DEFAULT_BUNDLE
|
|
14
13
|
import com.rnhotupdate.Common.PATH
|
|
15
14
|
import com.rnhotupdate.Common.VERSION
|
|
@@ -41,12 +40,22 @@ class OtaHotUpdate : BaseReactPackage() {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
companion object {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
fun Context.getVersionCode(): String {
|
|
44
|
+
return when {
|
|
45
|
+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> {
|
|
46
|
+
packageManager.getPackageInfo(
|
|
47
|
+
packageName,
|
|
48
|
+
PackageManager.PackageInfoFlags.of(0)
|
|
49
|
+
).longVersionCode.toString()
|
|
50
|
+
}
|
|
51
|
+
Build.VERSION.SDK_INT >= Build.VERSION_CODES.P -> {
|
|
52
|
+
@Suppress("DEPRECATION")
|
|
53
|
+
packageManager.getPackageInfo(packageName, 0).longVersionCode.toString()
|
|
54
|
+
}
|
|
55
|
+
else -> {
|
|
56
|
+
@Suppress("DEPRECATION")
|
|
57
|
+
packageManager.getPackageInfo(packageName, 0).versionCode.toString()
|
|
58
|
+
}
|
|
50
59
|
}
|
|
51
60
|
}
|
|
52
61
|
fun bundleJS(context: Context): String {
|
|
@@ -54,8 +63,8 @@ class OtaHotUpdate : BaseReactPackage() {
|
|
|
54
63
|
val sharedPrefs = SharedPrefs(context)
|
|
55
64
|
val pathBundle = sharedPrefs.getString(PATH)
|
|
56
65
|
val version = sharedPrefs.getString(VERSION)
|
|
57
|
-
val currentVersionName = sharedPrefs.getString(
|
|
58
|
-
if (pathBundle == "" || (currentVersionName != context.
|
|
66
|
+
val currentVersionName = sharedPrefs.getString(CURRENT_VERSION_CODE)
|
|
67
|
+
if (pathBundle == "" || (currentVersionName != context.getVersionCode())) {
|
|
59
68
|
if (version != "") {
|
|
60
69
|
// reset version number because bundle is wrong version, need download from new version
|
|
61
70
|
sharedPrefs.putString(VERSION, "")
|
|
@@ -5,8 +5,8 @@ import com.facebook.react.bridge.Promise
|
|
|
5
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
6
6
|
import com.facebook.react.bridge.ReactMethod
|
|
7
7
|
import com.jakewharton.processphoenix.ProcessPhoenix
|
|
8
|
-
import com.otahotupdate.OtaHotUpdate.Companion.
|
|
9
|
-
import com.rnhotupdate.Common.
|
|
8
|
+
import com.otahotupdate.OtaHotUpdate.Companion.getVersionCode
|
|
9
|
+
import com.rnhotupdate.Common.CURRENT_VERSION_CODE
|
|
10
10
|
import com.rnhotupdate.Common.PATH
|
|
11
11
|
import com.rnhotupdate.Common.PREVIOUS_PATH
|
|
12
12
|
import com.rnhotupdate.Common.VERSION
|
|
@@ -39,8 +39,8 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
39
39
|
}
|
|
40
40
|
sharedPrefs.putString(PATH, fileUnzip)
|
|
41
41
|
sharedPrefs.putString(
|
|
42
|
-
|
|
43
|
-
reactApplicationContext
|
|
42
|
+
CURRENT_VERSION_CODE,
|
|
43
|
+
reactApplicationContext.getVersionCode()
|
|
44
44
|
)
|
|
45
45
|
promise.resolve(true)
|
|
46
46
|
} else {
|
|
@@ -121,8 +121,8 @@ class OtaHotUpdateModule internal constructor(context: ReactApplicationContext)
|
|
|
121
121
|
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
122
122
|
sharedPrefs.putString(PATH, path)
|
|
123
123
|
sharedPrefs.putString(
|
|
124
|
-
|
|
125
|
-
reactApplicationContext
|
|
124
|
+
CURRENT_VERSION_CODE,
|
|
125
|
+
reactApplicationContext.getVersionCode()
|
|
126
126
|
)
|
|
127
127
|
promise.resolve(true)
|
|
128
128
|
}
|
|
@@ -28,7 +28,7 @@ object Common {
|
|
|
28
28
|
val PREVIOUS_PATH = "PREVIOUS_PATH"
|
|
29
29
|
val VERSION = "VERSION"
|
|
30
30
|
val PREVIOUS_VERSION = "PREVIOUS_VERSION"
|
|
31
|
-
val
|
|
31
|
+
val CURRENT_VERSION_CODE = "CURRENT_VERSION_CODE"
|
|
32
32
|
val SHARED_PREFERENCE_NAME = "HOT-UPDATE-REACT_NATIVE"
|
|
33
33
|
val DEFAULT_BUNDLE = "assets://index.android.bundle"
|
|
34
34
|
val METADATA = "METADATA"
|
package/ios/OtaHotUpdate.mm
CHANGED
|
@@ -133,6 +133,9 @@ void OTAExceptionHandler(NSException *exception) {
|
|
|
133
133
|
NSURL *fileURL = [NSURL fileURLWithPath:retrievedString];
|
|
134
134
|
return fileURL;
|
|
135
135
|
} else {
|
|
136
|
+
// reset version number because bundle is wrong version, need download from new version
|
|
137
|
+
[defaults removeObjectForKey:@"VERSION"];
|
|
138
|
+
[defaults synchronize];
|
|
136
139
|
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
137
140
|
}
|
|
138
141
|
}
|
package/package.json
CHANGED
package/plugin/build/index.js
CHANGED
|
@@ -3,20 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
4
|
const withAndroidAction = (config) => {
|
|
5
5
|
return (0, config_plugins_1.withMainApplication)(config, (config) => {
|
|
6
|
-
|
|
6
|
+
if (!config.modResults.contents.includes('override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)')) {
|
|
7
|
+
config.modResults.contents = config.modResults.contents.replace(/override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED/g, `
|
|
7
8
|
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
8
9
|
|
|
9
10
|
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`);
|
|
10
|
-
|
|
11
|
+
}
|
|
12
|
+
if (!config.modResults.contents.includes('import com.otahotupdate.OtaHotUpdate')) {
|
|
13
|
+
config.modResults.contents = config.modResults.contents.replace(/import expo.modules.ReactNativeHostWrapper/g, `
|
|
11
14
|
import expo.modules.ReactNativeHostWrapper
|
|
12
15
|
import com.otahotupdate.OtaHotUpdate`);
|
|
16
|
+
}
|
|
13
17
|
return config;
|
|
14
18
|
});
|
|
15
19
|
};
|
|
16
20
|
const withIosAction = (config) => {
|
|
17
21
|
return (0, config_plugins_1.withAppDelegate)(config, (config) => {
|
|
18
|
-
|
|
22
|
+
if (!config.modResults.contents.includes('#import "OtaHotUpdate.h')) {
|
|
23
|
+
config.modResults.contents = config.modResults.contents.replace(/#import "AppDelegate.h"/g, `#import "AppDelegate.h"
|
|
19
24
|
#import "OtaHotUpdate.h"`);
|
|
25
|
+
}
|
|
20
26
|
config.modResults.contents = config.modResults.contents.replace(/\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/, `[OtaHotUpdate getBundle]`);
|
|
21
27
|
return config;
|
|
22
28
|
});
|
package/plugin/src/index.ts
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import { withMainApplication, withAppDelegate } from '@expo/config-plugins';
|
|
2
2
|
const withAndroidAction: any = (config: any) => {
|
|
3
3
|
return withMainApplication(config, (config) => {
|
|
4
|
-
config.modResults.contents =
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
if (!config.modResults.contents.includes('override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)')) {
|
|
5
|
+
config.modResults.contents = config.modResults.contents.replace(
|
|
6
|
+
/override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED/g,
|
|
7
|
+
`
|
|
7
8
|
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
|
|
8
9
|
|
|
9
10
|
override fun getJSBundleFile(): String = OtaHotUpdate.bundleJS(this@MainApplication)`
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!config.modResults.contents.includes('import com.otahotupdate.OtaHotUpdate')) {
|
|
15
|
+
config.modResults.contents = config.modResults.contents.replace(
|
|
16
|
+
/import expo.modules.ReactNativeHostWrapper/g,
|
|
17
|
+
`
|
|
14
18
|
import expo.modules.ReactNativeHostWrapper
|
|
15
19
|
import com.otahotupdate.OtaHotUpdate`
|
|
16
|
-
|
|
20
|
+
);
|
|
21
|
+
}
|
|
17
22
|
return config;
|
|
18
23
|
});
|
|
19
24
|
};
|
|
20
25
|
|
|
21
26
|
const withIosAction: any = (config: any) => {
|
|
22
27
|
return withAppDelegate(config, (config) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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"
|
|
26
32
|
#import "OtaHotUpdate.h"`
|
|
27
|
-
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
28
36
|
config.modResults.contents = config.modResults.contents.replace(
|
|
29
37
|
/\[\[NSBundle mainBundle\] URLForResource:@\"main\" withExtension:@\"jsbundle\"\]/,
|
|
30
38
|
`[OtaHotUpdate getBundle]`
|