react-native-ota-hot-update 1.1.2 → 2.0.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/LICENSE +1 -2
- package/README.md +20 -8
- package/android/build.gradle +32 -4
- package/android/generated/java/com/otahotupdate/NativeOtaHotUpdateSpec.java +54 -0
- package/android/generated/jni/CMakeLists.txt +36 -0
- package/android/generated/jni/RNOtaHotUpdateSpec-generated.cpp +56 -0
- package/android/generated/jni/RNOtaHotUpdateSpec.h +31 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ComponentDescriptors.cpp +22 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ComponentDescriptors.h +24 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/EventEmitters.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/EventEmitters.h +17 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/Props.cpp +19 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/Props.h +18 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/RNOtaHotUpdateSpecJSI-generated.cpp +56 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/RNOtaHotUpdateSpecJSI.h +103 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ShadowNodes.cpp +17 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/ShadowNodes.h +23 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/States.cpp +16 -0
- package/android/generated/jni/react/renderer/components/RNOtaHotUpdateSpec/States.h +19 -0
- package/android/gradle.properties +5 -5
- package/android/src/main/AndroidManifest.xml +1 -1
- package/android/src/main/java/com/otahotupdate/OtaHotUpdate.kt +57 -0
- package/android/src/main/java/com/otahotupdate/OtaHotUpdateModule.kt +142 -0
- package/android/src/newarch/OtaHotUpdateSpec.kt +7 -0
- package/android/src/oldarch/OtaHotUpdateSpec.kt +15 -0
- package/ios/OtaHotUpdate.h +13 -0
- package/ios/{RNhotupdate.m → OtaHotUpdate.mm} +50 -33
- package/ios/generated/RNOtaHotUpdateSpec/ComponentDescriptors.cpp +22 -0
- package/ios/generated/RNOtaHotUpdateSpec/ComponentDescriptors.h +24 -0
- package/ios/generated/RNOtaHotUpdateSpec/EventEmitters.cpp +16 -0
- package/ios/generated/RNOtaHotUpdateSpec/EventEmitters.h +17 -0
- package/ios/generated/RNOtaHotUpdateSpec/Props.cpp +19 -0
- package/ios/generated/RNOtaHotUpdateSpec/Props.h +18 -0
- package/ios/generated/RNOtaHotUpdateSpec/RCTComponentViewHelpers.h +18 -0
- package/ios/generated/RNOtaHotUpdateSpec/RNOtaHotUpdateSpec-generated.mm +67 -0
- package/ios/generated/RNOtaHotUpdateSpec/RNOtaHotUpdateSpec.h +72 -0
- package/ios/generated/RNOtaHotUpdateSpec/ShadowNodes.cpp +17 -0
- package/ios/generated/RNOtaHotUpdateSpec/ShadowNodes.h +23 -0
- package/ios/generated/RNOtaHotUpdateSpec/States.cpp +16 -0
- package/ios/generated/RNOtaHotUpdateSpec/States.h +19 -0
- package/ios/generated/RNOtaHotUpdateSpecJSI-generated.cpp +56 -0
- package/ios/generated/RNOtaHotUpdateSpecJSI.h +103 -0
- package/lib/commonjs/NativeOtaHotUpdate.js +9 -0
- package/lib/commonjs/NativeOtaHotUpdate.js.map +1 -0
- package/lib/commonjs/download.d.js +2 -0
- package/lib/commonjs/download.d.js.map +1 -0
- package/lib/commonjs/index.js +113 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/module/NativeOtaHotUpdate.js +5 -0
- package/lib/module/NativeOtaHotUpdate.js.map +1 -0
- package/lib/module/download.d.js +2 -0
- package/lib/module/download.d.js.map +1 -0
- package/lib/module/index.js +109 -0
- package/lib/module/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeOtaHotUpdate.d.ts +11 -0
- package/lib/typescript/commonjs/src/NativeOtaHotUpdate.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +25 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/NativeOtaHotUpdate.d.ts +11 -0
- package/lib/typescript/module/src/NativeOtaHotUpdate.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +25 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/package.json +184 -12
- package/{rn-hotupdate.podspec → react-native-ota-hot-update.podspec} +3 -3
- package/react-native.config.js +10 -6
- package/src/NativeOtaHotUpdate.ts +12 -0
- package/src/download.d.ts +759 -689
- package/src/index.tsx +67 -39
- package/android/src/main/java/com/rnhotupdate/HotUpdateModule.java +0 -161
- package/android/src/main/java/com/rnhotupdate/OtaHotUpdate.java +0 -45
- package/ios/RNhotupdate.h +0 -12
- package/ios/RNhotupdate.xcodeproj/project.pbxproj +0 -281
- package/ios/RNhotupdate.xcworkspace/contents.xcworkspacedata +0 -7
- /package/android/src/main/java/com/{rnhotupdate → otahotupdate}/SharedPrefs.kt +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateStateCpp.js
|
|
9
|
+
*/
|
|
10
|
+
#include "States.h"
|
|
11
|
+
|
|
12
|
+
namespace facebook::react {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateStateH.js
|
|
8
|
+
*/
|
|
9
|
+
#pragma once
|
|
10
|
+
|
|
11
|
+
#ifdef ANDROID
|
|
12
|
+
#include <folly/dynamic.h>
|
|
13
|
+
#endif
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::react
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
OtaHotUpdate_kotlinVersion=1.7.0
|
|
2
|
+
OtaHotUpdate_minSdkVersion=21
|
|
3
|
+
OtaHotUpdate_targetSdkVersion=31
|
|
4
|
+
OtaHotUpdate_compileSdkVersion=31
|
|
5
|
+
OtaHotUpdate_ndkversion=21.4.7075529
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
package com.otahotupdate
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.facebook.react.TurboReactPackage
|
|
5
|
+
import com.facebook.react.bridge.NativeModule
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
|
8
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
|
9
|
+
import com.rnhotupdate.Common.DEFAULT_BUNDLE
|
|
10
|
+
import com.rnhotupdate.Common.PATH
|
|
11
|
+
import com.rnhotupdate.SharedPrefs
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class OtaHotUpdate(context: Context?) : TurboReactPackage() {
|
|
15
|
+
init {
|
|
16
|
+
mContext = context
|
|
17
|
+
}
|
|
18
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
|
19
|
+
return if (name == OtaHotUpdateModule.NAME) {
|
|
20
|
+
OtaHotUpdateModule(reactContext)
|
|
21
|
+
} else {
|
|
22
|
+
null
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
|
27
|
+
return ReactModuleInfoProvider {
|
|
28
|
+
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
|
|
29
|
+
val isTurboModule: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
|
|
30
|
+
moduleInfos[OtaHotUpdateModule.NAME] = ReactModuleInfo(
|
|
31
|
+
OtaHotUpdateModule.NAME,
|
|
32
|
+
OtaHotUpdateModule.NAME,
|
|
33
|
+
false, // canOverrideExistingModule
|
|
34
|
+
false, // needsEagerInit
|
|
35
|
+
true, // hasConstants
|
|
36
|
+
false, // isCxxModule
|
|
37
|
+
isTurboModule // isTurboModule
|
|
38
|
+
)
|
|
39
|
+
moduleInfos
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
companion object {
|
|
43
|
+
private var mContext: Context? = null
|
|
44
|
+
val bundleJS: String
|
|
45
|
+
get() {
|
|
46
|
+
if (mContext == null) {
|
|
47
|
+
return DEFAULT_BUNDLE
|
|
48
|
+
}
|
|
49
|
+
val sharedPrefs = SharedPrefs(mContext!!)
|
|
50
|
+
val pathBundle = sharedPrefs.getString(PATH)
|
|
51
|
+
if (pathBundle == "") {
|
|
52
|
+
return DEFAULT_BUNDLE
|
|
53
|
+
}
|
|
54
|
+
return pathBundle!!
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
package com.otahotupdate
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
+
import com.facebook.react.bridge.ReactMethod
|
|
8
|
+
import com.jakewharton.processphoenix.ProcessPhoenix
|
|
9
|
+
import com.rnhotupdate.Common.PATH
|
|
10
|
+
import com.rnhotupdate.Common.VERSION
|
|
11
|
+
import com.rnhotupdate.SharedPrefs
|
|
12
|
+
import java.io.File
|
|
13
|
+
import java.util.zip.ZipFile
|
|
14
|
+
|
|
15
|
+
class OtaHotUpdateModule internal constructor(context: ReactApplicationContext) :
|
|
16
|
+
OtaHotUpdateSpec(context) {
|
|
17
|
+
|
|
18
|
+
override fun getName(): String {
|
|
19
|
+
return NAME
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private fun deleteDirectory(directory: File): Boolean {
|
|
23
|
+
if (directory.isDirectory) {
|
|
24
|
+
// List all files and directories in the current directory
|
|
25
|
+
val files = directory.listFiles()
|
|
26
|
+
if (files != null) {
|
|
27
|
+
// Recursively delete all files and directories
|
|
28
|
+
for (file in files) {
|
|
29
|
+
if (!deleteDirectory(file)) {
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Finally, delete the empty directory or file
|
|
36
|
+
return directory.delete()
|
|
37
|
+
}
|
|
38
|
+
private fun deleteOldBundleIfneeded(): Boolean {
|
|
39
|
+
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
40
|
+
val path = sharedPrefs.getString(PATH)
|
|
41
|
+
val file = File(path)
|
|
42
|
+
if (file.exists() && file.isFile) {
|
|
43
|
+
val isDeleted = deleteDirectory(file.parentFile)
|
|
44
|
+
sharedPrefs.clear()
|
|
45
|
+
return isDeleted
|
|
46
|
+
} else {
|
|
47
|
+
return false
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
private fun extractZipFile(
|
|
51
|
+
zipFile: File,extension: String
|
|
52
|
+
): String? {
|
|
53
|
+
return try {
|
|
54
|
+
val outputDir = zipFile.parentFile
|
|
55
|
+
var bundlePath: String? = null
|
|
56
|
+
ZipFile(zipFile).use { zip ->
|
|
57
|
+
zip.entries().asSequence().forEach { entry ->
|
|
58
|
+
zip.getInputStream(entry).use { input ->
|
|
59
|
+
if (entry.isDirectory) {
|
|
60
|
+
val d = File(outputDir, entry.name)
|
|
61
|
+
if (!d.exists()) d.mkdirs()
|
|
62
|
+
} else {
|
|
63
|
+
val f = File(outputDir, entry.name)
|
|
64
|
+
if (f.parentFile?.exists() != true) f.parentFile?.mkdirs()
|
|
65
|
+
|
|
66
|
+
f.outputStream().use { output ->
|
|
67
|
+
input.copyTo(output)
|
|
68
|
+
}
|
|
69
|
+
if (f.absolutePath.contains(extension)) {
|
|
70
|
+
bundlePath = f.absolutePath
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
bundlePath
|
|
77
|
+
} catch (e: Exception) {
|
|
78
|
+
e.printStackTrace()
|
|
79
|
+
null
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@ReactMethod
|
|
85
|
+
override fun setupBundlePath(path: String?, extension: String?, promise: Promise) {
|
|
86
|
+
if (path != null) {
|
|
87
|
+
deleteOldBundleIfneeded()
|
|
88
|
+
val file = File(path)
|
|
89
|
+
if (file.exists() && file.isFile) {
|
|
90
|
+
val fileUnzip = extractZipFile(file, extension ?: ".bundle")
|
|
91
|
+
Log.d("setupBundlePath----: ", fileUnzip!!)
|
|
92
|
+
if (fileUnzip != null) {
|
|
93
|
+
file.delete()
|
|
94
|
+
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
95
|
+
sharedPrefs.putString(PATH, fileUnzip)
|
|
96
|
+
promise.resolve(true)
|
|
97
|
+
} else {
|
|
98
|
+
promise.resolve(false)
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
promise.resolve(false)
|
|
102
|
+
}
|
|
103
|
+
} else {
|
|
104
|
+
promise.resolve(false)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@ReactMethod
|
|
109
|
+
override fun deleteBundle(i: Double, promise: Promise) {
|
|
110
|
+
val isDeleted = deleteOldBundleIfneeded()
|
|
111
|
+
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
112
|
+
sharedPrefs.putString(VERSION, "0")
|
|
113
|
+
promise.resolve(isDeleted)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@ReactMethod
|
|
117
|
+
override fun restart() {
|
|
118
|
+
val context: Context? = currentActivity
|
|
119
|
+
ProcessPhoenix.triggerRebirth(context);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@ReactMethod
|
|
123
|
+
override fun getCurrentVersion(a: Double, promise: Promise) {
|
|
124
|
+
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
125
|
+
val version = sharedPrefs.getString(VERSION)
|
|
126
|
+
if (version != "") {
|
|
127
|
+
promise.resolve(version)
|
|
128
|
+
} else {
|
|
129
|
+
promise.resolve("0")
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@ReactMethod
|
|
134
|
+
override fun setCurrentVersion(version: String?, promise: Promise) {
|
|
135
|
+
val sharedPrefs = SharedPrefs(reactApplicationContext)
|
|
136
|
+
sharedPrefs.putString(VERSION, version)
|
|
137
|
+
promise.resolve(true)
|
|
138
|
+
}
|
|
139
|
+
companion object {
|
|
140
|
+
const val NAME = "OtaHotUpdate"
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.otahotupdate
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
|
5
|
+
import com.facebook.react.bridge.Promise
|
|
6
|
+
|
|
7
|
+
abstract class OtaHotUpdateSpec internal constructor(context: ReactApplicationContext) :
|
|
8
|
+
ReactContextBaseJavaModule(context) {
|
|
9
|
+
|
|
10
|
+
abstract fun setupBundlePath(path: String, extension: String?, promise: Promise)
|
|
11
|
+
abstract fun deleteBundle(i: Number, promise: Promise)
|
|
12
|
+
abstract fun restart()
|
|
13
|
+
abstract fun getCurrentVersion(a: Number, promise: Promise)
|
|
14
|
+
abstract fun setCurrentVersion(version: String, promise: Promise)
|
|
15
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#import <React/RCTReloadCommand.h>
|
|
2
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
3
|
+
#import "RNOtaHotUpdateSpec.h"
|
|
4
|
+
|
|
5
|
+
@interface OtaHotUpdate : NSObject <NativeOtaHotUpdateSpec>
|
|
6
|
+
#else
|
|
7
|
+
#import <React/RCTBridgeModule.h>
|
|
8
|
+
|
|
9
|
+
@interface OtaHotUpdate : NSObject <RCTBridgeModule>
|
|
10
|
+
#endif
|
|
11
|
+
+ (NSURL *)getBundle;
|
|
12
|
+
|
|
13
|
+
@end
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
#import "
|
|
2
|
-
#import <React/RCTLog.h>
|
|
1
|
+
#import "OtaHotUpdate.h"
|
|
3
2
|
#import <SSZipArchive/SSZipArchive.h>
|
|
4
|
-
|
|
5
|
-
@implementation RNhotupdate
|
|
3
|
+
@implementation OtaHotUpdate
|
|
6
4
|
RCT_EXPORT_MODULE()
|
|
7
5
|
|
|
8
6
|
// Check if a file path is valid
|
|
@@ -11,31 +9,16 @@ RCT_EXPORT_MODULE()
|
|
|
11
9
|
return [fileManager fileExistsAtPath:path];
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
- (BOOL)removeBundleIfNeeded {
|
|
15
|
-
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
16
|
-
NSString *retrievedString = [defaults stringForKey:@"PATH"];
|
|
17
|
-
NSError *error = nil;
|
|
18
|
-
if (retrievedString && [self isFilePathValid:retrievedString]) {
|
|
19
|
-
BOOL isDeleted = [self deleteAllContentsOfParentDirectoryOfFile:retrievedString error:&error];
|
|
20
|
-
[defaults removeObjectForKey:@"PATH"];
|
|
21
|
-
[defaults synchronize];
|
|
22
|
-
return isDeleted;
|
|
23
|
-
} else {
|
|
24
|
-
return NO;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
12
|
// Delete a file at the specified path
|
|
29
13
|
- (BOOL)deleteFileAtPath:(NSString *)path {
|
|
30
14
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
31
15
|
NSError *error = nil;
|
|
32
16
|
BOOL success = [fileManager removeItemAtPath:path error:&error];
|
|
33
17
|
if (!success) {
|
|
34
|
-
|
|
18
|
+
NSLog(@"Error deleting file: %@", [error localizedDescription]);
|
|
35
19
|
}
|
|
36
20
|
return success;
|
|
37
21
|
}
|
|
38
|
-
|
|
39
22
|
- (BOOL)deleteAllContentsOfParentDirectoryOfFile:(NSString *)filePath error:(NSError **)error {
|
|
40
23
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
41
24
|
|
|
@@ -82,6 +65,21 @@ RCT_EXPORT_MODULE()
|
|
|
82
65
|
|
|
83
66
|
return success;
|
|
84
67
|
}
|
|
68
|
+
|
|
69
|
+
- (BOOL)removeBundleIfNeeded {
|
|
70
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
71
|
+
NSString *retrievedString = [defaults stringForKey:@"PATH"];
|
|
72
|
+
NSError *error = nil;
|
|
73
|
+
if (retrievedString && [self isFilePathValid:retrievedString]) {
|
|
74
|
+
BOOL isDeleted = [self deleteAllContentsOfParentDirectoryOfFile:retrievedString error:&error];
|
|
75
|
+
[defaults removeObjectForKey:@"PATH"];
|
|
76
|
+
[defaults synchronize];
|
|
77
|
+
return isDeleted;
|
|
78
|
+
} else {
|
|
79
|
+
return NO;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
85
83
|
+ (BOOL)isFilePathExist:(NSString *)path {
|
|
86
84
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
87
85
|
return [fileManager fileExistsAtPath:path];
|
|
@@ -97,6 +95,7 @@ RCT_EXPORT_MODULE()
|
|
|
97
95
|
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
|
|
98
96
|
}
|
|
99
97
|
}
|
|
98
|
+
|
|
100
99
|
- (NSString *)searchForJsBundleInDirectory:(NSString *)directoryPath extension:(NSString *)extension {
|
|
101
100
|
NSFileManager *fileManager = [NSFileManager defaultManager];
|
|
102
101
|
NSError *error;
|
|
@@ -165,7 +164,9 @@ RCT_EXPORT_MODULE()
|
|
|
165
164
|
}
|
|
166
165
|
|
|
167
166
|
// Expose setupBundlePath method to JavaScript
|
|
168
|
-
RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extension
|
|
167
|
+
RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extension
|
|
168
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
169
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
169
170
|
if ([self isFilePathValid:path]) {
|
|
170
171
|
[self removeBundleIfNeeded];
|
|
171
172
|
//Unzip file
|
|
@@ -183,24 +184,30 @@ RCT_EXPORT_METHOD(setupBundlePath:(NSString *)path extension:(NSString *)extensi
|
|
|
183
184
|
resolve(@(NO));
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
|
-
|
|
187
187
|
// Expose deleteBundle method to JavaScript
|
|
188
|
-
RCT_EXPORT_METHOD(deleteBundle:(
|
|
188
|
+
RCT_EXPORT_METHOD(deleteBundle:(double)i
|
|
189
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
190
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
189
191
|
BOOL isDeleted = [self removeBundleIfNeeded];
|
|
190
192
|
resolve(@(isDeleted));
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
RCT_EXPORT_METHOD(getCurrentVersion:(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
195
|
+
RCT_EXPORT_METHOD(getCurrentVersion:(double)a
|
|
196
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
197
|
+
reject:(RCTPromiseRejectBlock)reject)
|
|
198
|
+
{
|
|
199
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
200
|
+
NSString *version = [defaults stringForKey:@"VERSION"];
|
|
201
|
+
if (version) {
|
|
202
|
+
resolve(version);
|
|
203
|
+
} else {
|
|
204
|
+
resolve(@"0");
|
|
205
|
+
}
|
|
201
206
|
}
|
|
202
207
|
|
|
203
|
-
RCT_EXPORT_METHOD(setCurrentVersion:(NSString *)version
|
|
208
|
+
RCT_EXPORT_METHOD(setCurrentVersion:(NSString *)version
|
|
209
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
210
|
+
reject:(RCTPromiseRejectBlock)reject) {
|
|
204
211
|
if (version) {
|
|
205
212
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
206
213
|
[defaults setObject:version forKey:@"VERSION"];
|
|
@@ -213,7 +220,7 @@ RCT_EXPORT_METHOD(setCurrentVersion:(NSString *)version withResolver:(RCTPromise
|
|
|
213
220
|
|
|
214
221
|
- (void)loadBundle
|
|
215
222
|
{
|
|
216
|
-
RCTTriggerReloadCommandListeners(@"
|
|
223
|
+
RCTTriggerReloadCommandListeners(@"react-native-ota-hot-update: Restart");
|
|
217
224
|
}
|
|
218
225
|
RCT_EXPORT_METHOD(restart) {
|
|
219
226
|
if ([NSThread isMainThread]) {
|
|
@@ -226,4 +233,14 @@ RCT_EXPORT_METHOD(restart) {
|
|
|
226
233
|
return;
|
|
227
234
|
}
|
|
228
235
|
|
|
236
|
+
|
|
237
|
+
// Don't compile this code when we build for the old architecture.
|
|
238
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
239
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
240
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
241
|
+
{
|
|
242
|
+
return std::make_shared<facebook::react::NativeOtaHotUpdateSpecJSI>(params);
|
|
243
|
+
}
|
|
244
|
+
#endif
|
|
245
|
+
|
|
229
246
|
@end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateComponentDescriptorCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "ComponentDescriptors.h"
|
|
12
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
13
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
void RNOtaHotUpdateSpec_registerComponentDescriptorsFromCodegen(
|
|
18
|
+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry) {
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateComponentDescriptorH.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#pragma once
|
|
12
|
+
|
|
13
|
+
#include "ShadowNodes.h"
|
|
14
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
15
|
+
#include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
|
|
16
|
+
|
|
17
|
+
namespace facebook::react {
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
void RNOtaHotUpdateSpec_registerComponentDescriptorsFromCodegen(
|
|
22
|
+
std::shared_ptr<const ComponentDescriptorProviderRegistry> registry);
|
|
23
|
+
|
|
24
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateEventEmitterCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "EventEmitters.h"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace facebook::react {
|
|
15
|
+
|
|
16
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GenerateEventEmitterH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
#include <react/renderer/components/view/ViewEventEmitter.h>
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsCpp.js
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "Props.h"
|
|
12
|
+
#include <react/renderer/core/PropsParserContext.h>
|
|
13
|
+
#include <react/renderer/core/propsConversions.h>
|
|
14
|
+
|
|
15
|
+
namespace facebook::react {
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
|
+
*
|
|
5
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
6
|
+
* once the code is regenerated.
|
|
7
|
+
*
|
|
8
|
+
* @generated by codegen project: GeneratePropsH.js
|
|
9
|
+
*/
|
|
10
|
+
#pragma once
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
namespace facebook::react {
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateComponentHObjCpp.js
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#import <Foundation/Foundation.h>
|
|
11
|
+
#import <React/RCTDefines.h>
|
|
12
|
+
#import <React/RCTLog.h>
|
|
13
|
+
|
|
14
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
3
|
+
*
|
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
|
5
|
+
* once the code is regenerated.
|
|
6
|
+
*
|
|
7
|
+
* @generated by codegen project: GenerateModuleObjCpp
|
|
8
|
+
*
|
|
9
|
+
* We create an umbrella header (and corresponding implementation) here since
|
|
10
|
+
* Cxx compilation in BUCK has a limitation: source-code producing genrule()s
|
|
11
|
+
* must have a single output. More files => more genrule()s => slower builds.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#import "RNOtaHotUpdateSpec.h"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@implementation NativeOtaHotUpdateSpecBase
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
- (void)setEventEmitterCallback:(EventEmitterCallbackWrapper *)eventEmitterCallbackWrapper
|
|
21
|
+
{
|
|
22
|
+
_eventEmitterCallback = std::move(eventEmitterCallbackWrapper->_eventEmitterCallback);
|
|
23
|
+
}
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
namespace facebook::react {
|
|
28
|
+
|
|
29
|
+
static facebook::jsi::Value __hostFunction_NativeOtaHotUpdateSpecJSI_setupBundlePath(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
30
|
+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "setupBundlePath", @selector(setupBundlePath:extension:resolve:reject:), args, count);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static facebook::jsi::Value __hostFunction_NativeOtaHotUpdateSpecJSI_deleteBundle(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
34
|
+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "deleteBundle", @selector(deleteBundle:resolve:reject:), args, count);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static facebook::jsi::Value __hostFunction_NativeOtaHotUpdateSpecJSI_restart(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
38
|
+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, VoidKind, "restart", @selector(restart), args, count);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static facebook::jsi::Value __hostFunction_NativeOtaHotUpdateSpecJSI_getCurrentVersion(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
42
|
+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "getCurrentVersion", @selector(getCurrentVersion:resolve:reject:), args, count);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static facebook::jsi::Value __hostFunction_NativeOtaHotUpdateSpecJSI_setCurrentVersion(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
|
46
|
+
return static_cast<ObjCTurboModule&>(turboModule).invokeObjCMethod(rt, PromiseKind, "setCurrentVersion", @selector(setCurrentVersion:resolve:reject:), args, count);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
NativeOtaHotUpdateSpecJSI::NativeOtaHotUpdateSpecJSI(const ObjCTurboModule::InitParams ¶ms)
|
|
50
|
+
: ObjCTurboModule(params) {
|
|
51
|
+
|
|
52
|
+
methodMap_["setupBundlePath"] = MethodMetadata {2, __hostFunction_NativeOtaHotUpdateSpecJSI_setupBundlePath};
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
methodMap_["deleteBundle"] = MethodMetadata {1, __hostFunction_NativeOtaHotUpdateSpecJSI_deleteBundle};
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
methodMap_["restart"] = MethodMetadata {0, __hostFunction_NativeOtaHotUpdateSpecJSI_restart};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
methodMap_["getCurrentVersion"] = MethodMetadata {1, __hostFunction_NativeOtaHotUpdateSpecJSI_getCurrentVersion};
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
methodMap_["setCurrentVersion"] = MethodMetadata {1, __hostFunction_NativeOtaHotUpdateSpecJSI_setCurrentVersion};
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
} // namespace facebook::react
|