@viettelpost/react-native-ota 0.1.0 → 0.1.2
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/build.gradle +1 -0
- package/android/src/main/java/com/viettelpost/otakit/OTAUpdateModule.kt +3 -3
- package/ios/OTAUpdateBundleResolver.swift +5 -5
- package/ios/OTAUpdateCleanup.swift +4 -4
- package/ios/OTAUpdateDownloader.swift +4 -4
- package/ios/OTAUpdateModule.mm +2 -2
- package/ios/OTAUpdateStorage.swift +4 -4
- package/lib/NativeOTAUpdate.js +12 -12
- package/package.json +1 -1
- package/react-native-ota.podspec +1 -0
- package/src/NativeOTAUpdate.ts +1 -1
- /package/lib/spec/{NativeOTAUpdate.d.ts → NativeReactNativeOta.d.ts} +0 -0
- /package/lib/spec/{NativeOTAUpdate.js → NativeReactNativeOta.js} +0 -0
- /package/src/spec/{NativeOTAUpdate.ts → NativeReactNativeOta.ts} +0 -0
package/android/build.gradle
CHANGED
|
@@ -3,10 +3,10 @@ package com.viettelpost.otakit
|
|
|
3
3
|
import com.facebook.react.bridge.Promise
|
|
4
4
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
5
5
|
import com.facebook.react.module.annotations.ReactModule
|
|
6
|
-
import com.viettelpost.otakit.
|
|
6
|
+
import com.viettelpost.otakit.NativeReactNativeOtaSpec
|
|
7
7
|
|
|
8
8
|
@ReactModule(name = OTAUpdateModule.NAME)
|
|
9
|
-
class OTAUpdateModule(reactContext: ReactApplicationContext) :
|
|
9
|
+
class OTAUpdateModule(reactContext: ReactApplicationContext) : NativeReactNativeOtaSpec(reactContext) {
|
|
10
10
|
override fun getMetadata(promise: Promise) {
|
|
11
11
|
try {
|
|
12
12
|
val metadata = OTAUpdateStorage.readMetadata(reactApplicationContext)
|
|
@@ -135,6 +135,6 @@ class OTAUpdateModule(reactContext: ReactApplicationContext) : NativeOTAUpdateSp
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
companion object {
|
|
138
|
-
const val NAME: String =
|
|
138
|
+
const val NAME: String = NativeReactNativeOtaSpec.NAME
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -52,7 +52,7 @@ public final class OTAUpdateBundleResolver: NSObject {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
@objc func getOTADirectoryPath() throws -> String {
|
|
55
|
+
@objc public func getOTADirectoryPath() throws -> String {
|
|
56
56
|
let directoryURL = try otaDirectoryURL()
|
|
57
57
|
try fileManager.createDirectory(
|
|
58
58
|
at: directoryURL,
|
|
@@ -63,7 +63,7 @@ public final class OTAUpdateBundleResolver: NSObject {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
// Manual test hook: the bundle file must already be copied into private OTA storage.
|
|
66
|
-
@objc func prepareManualInstall(_ bundleVersion: String) throws -> NSNumber {
|
|
66
|
+
@objc public func prepareManualInstall(_ bundleVersion: String) throws -> NSNumber {
|
|
67
67
|
let normalizedVersion = bundleVersion.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
68
68
|
guard !normalizedVersion.isEmpty else {
|
|
69
69
|
throw NSError(
|
|
@@ -93,7 +93,7 @@ public final class OTAUpdateBundleResolver: NSObject {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
// Manual test hook: promote only the pending bundle that actually launched.
|
|
96
|
-
@objc func markSuccess() throws -> NSNumber {
|
|
96
|
+
@objc public func markSuccess() throws -> NSNumber {
|
|
97
97
|
var metadata = try storage.readMetadata()
|
|
98
98
|
guard metadata.status == statusPending,
|
|
99
99
|
let pendingVersion = metadata.pendingBundleVersion,
|
|
@@ -121,7 +121,7 @@ public final class OTAUpdateBundleResolver: NSObject {
|
|
|
121
121
|
return true as NSNumber
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
@objc func copyBundleFromDocuments(_ bundleVersion: String, fileName: String) throws -> NSNumber {
|
|
124
|
+
@objc public func copyBundleFromDocuments(_ bundleVersion: String, fileName: String) throws -> NSNumber {
|
|
125
125
|
let normalizedVersion = bundleVersion.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
126
126
|
let normalizedFileName = fileName.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
127
127
|
guard !normalizedVersion.isEmpty, !normalizedFileName.isEmpty else {
|
|
@@ -160,7 +160,7 @@ public final class OTAUpdateBundleResolver: NSObject {
|
|
|
160
160
|
return true as NSNumber
|
|
161
161
|
}
|
|
162
162
|
|
|
163
|
-
@objc func getCurrentBundleInfoJSONString() throws -> String {
|
|
163
|
+
@objc public func getCurrentBundleInfoJSONString() throws -> String {
|
|
164
164
|
let metadata = try storage.readMetadata()
|
|
165
165
|
let info = currentBundleInfo(for: metadata)
|
|
166
166
|
let data = try encoder.encode(info)
|
|
@@ -17,8 +17,8 @@ struct OTADiskUsage: Codable {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
@objc(OTAUpdateCleanup)
|
|
20
|
-
final class OTAUpdateCleanup: NSObject {
|
|
21
|
-
@objc static let shared = OTAUpdateCleanup()
|
|
20
|
+
public final class OTAUpdateCleanup: NSObject {
|
|
21
|
+
@objc public static let shared = OTAUpdateCleanup()
|
|
22
22
|
|
|
23
23
|
private let fileManager: FileManager
|
|
24
24
|
private let encoder: JSONEncoder
|
|
@@ -69,7 +69,7 @@ final class OTAUpdateCleanup: NSObject {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
-
@objc func cleanupOTAStorage() throws -> NSNumber {
|
|
72
|
+
@objc public func cleanupOTAStorage() throws -> NSNumber {
|
|
73
73
|
let metadata = try storage.readMetadata()
|
|
74
74
|
var keepVersions = Set<String>()
|
|
75
75
|
if !isEmbeddedVersion(metadata.activeBundleVersion) {
|
|
@@ -89,7 +89,7 @@ final class OTAUpdateCleanup: NSObject {
|
|
|
89
89
|
return didCleanup as NSNumber
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
@objc func getOTADiskUsageJSONString() throws -> String {
|
|
92
|
+
@objc public func getOTADiskUsageJSONString() throws -> String {
|
|
93
93
|
let usage = try getOTADiskUsage()
|
|
94
94
|
let data = try encoder.encode(usage)
|
|
95
95
|
guard let json = String(data: data, encoding: .utf8) else {
|
|
@@ -55,8 +55,8 @@ private struct OTAUpdatePayload {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
@objc(OTAUpdateDownloader)
|
|
58
|
-
final class OTAUpdateDownloader: NSObject {
|
|
59
|
-
@objc static let shared = OTAUpdateDownloader()
|
|
58
|
+
public final class OTAUpdateDownloader: NSObject {
|
|
59
|
+
@objc public static let shared = OTAUpdateDownloader()
|
|
60
60
|
|
|
61
61
|
private let storage = OTAUpdateStorage.shared
|
|
62
62
|
private let fileManager = FileManager.default
|
|
@@ -87,7 +87,7 @@ final class OTAUpdateDownloader: NSObject {
|
|
|
87
87
|
private let reasonTempAssetsNotFoundForVerify = "temp_assets_not_found_for_verify"
|
|
88
88
|
private let signatureMismatchMessage = "OTA signature mismatch. Check that version, platform, fileName, lowercase sha256, and assetsSha256 when assets are included exactly match the signed payload."
|
|
89
89
|
|
|
90
|
-
@objc func downloadAndInstallBundle(_ updateJson: String, completion: @escaping (NSNumber?, NSError?) -> Void) {
|
|
90
|
+
@objc public func downloadAndInstallBundle(_ updateJson: String, completion: @escaping (NSNumber?, NSError?) -> Void) {
|
|
91
91
|
DispatchQueue.global(qos: .utility).async {
|
|
92
92
|
do {
|
|
93
93
|
_ = try self.downloadBundle(updateJson)
|
|
@@ -99,7 +99,7 @@ final class OTAUpdateDownloader: NSObject {
|
|
|
99
99
|
}
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
@objc func getDownloadInfo(_ version: String) throws -> String {
|
|
102
|
+
@objc public func getDownloadInfo(_ version: String) throws -> String {
|
|
103
103
|
let normalizedVersion = try normalizeVersion(version)
|
|
104
104
|
let tempBundleURL = try tempBundleURL(version: normalizedVersion)
|
|
105
105
|
let finalBundleURL = try finalBundleURL(version: normalizedVersion)
|
package/ios/OTAUpdateModule.mm
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
#import "ReactNativeOta-Swift.h"
|
|
7
7
|
#import <ReactNativeOtaSpec/ReactNativeOtaSpec.h>
|
|
8
8
|
|
|
9
|
-
@interface OTAUpdateModule : NSObject <
|
|
9
|
+
@interface OTAUpdateModule : NSObject <NativeReactNativeOtaSpec>
|
|
10
10
|
@end
|
|
11
11
|
|
|
12
12
|
@implementation OTAUpdateModule
|
|
@@ -183,7 +183,7 @@ static NSString *OTARejectMessageFromError(NSError *error, NSString *fallbackMes
|
|
|
183
183
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
184
184
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
185
185
|
{
|
|
186
|
-
return std::make_shared<facebook::react::
|
|
186
|
+
return std::make_shared<facebook::react::NativeReactNativeOtaSpecJSI>(params);
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
@end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
|
|
3
3
|
@objc(OTAUpdateStorage)
|
|
4
|
-
final class OTAUpdateStorage: NSObject {
|
|
5
|
-
@objc static let shared = OTAUpdateStorage()
|
|
4
|
+
public final class OTAUpdateStorage: NSObject {
|
|
5
|
+
@objc public static let shared = OTAUpdateStorage()
|
|
6
6
|
|
|
7
7
|
private let encoder: JSONEncoder
|
|
8
8
|
private let decoder: JSONDecoder
|
|
@@ -15,7 +15,7 @@ final class OTAUpdateStorage: NSObject {
|
|
|
15
15
|
super.init()
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
@objc func getMetadataJSONString() throws -> String {
|
|
18
|
+
@objc public func getMetadataJSONString() throws -> String {
|
|
19
19
|
let metadata = try readMetadata()
|
|
20
20
|
let data = try encoder.encode(metadata)
|
|
21
21
|
guard let jsonString = String(data: data, encoding: .utf8) else {
|
|
@@ -24,7 +24,7 @@ final class OTAUpdateStorage: NSObject {
|
|
|
24
24
|
return jsonString
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
@objc func resetMetadata() throws -> NSNumber {
|
|
27
|
+
@objc public func resetMetadata() throws -> NSNumber {
|
|
28
28
|
try writeMetadata(.default())
|
|
29
29
|
return true as NSNumber
|
|
30
30
|
}
|
package/lib/NativeOTAUpdate.js
CHANGED
|
@@ -5,55 +5,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.cleanupOTAStorage = exports.getOTADiskUsage = exports.getDownloadInfo = exports.downloadAndInstallBundle = exports.getCurrentBundleInfo = exports.copyBundleFromDocuments = exports.markOTASuccess = exports.prepareManualInstall = exports.getOTADirectory = exports.resetOTAMetadata = exports.getOTAMetadata = void 0;
|
|
7
7
|
const react_native_1 = require("react-native");
|
|
8
|
-
const
|
|
8
|
+
const NativeReactNativeOta_1 = __importDefault(require("./spec/NativeReactNativeOta"));
|
|
9
9
|
async function getOTAMetadata() {
|
|
10
|
-
const metadata = await
|
|
10
|
+
const metadata = await NativeReactNativeOta_1.default.getMetadata();
|
|
11
11
|
return JSON.parse(metadata);
|
|
12
12
|
}
|
|
13
13
|
exports.getOTAMetadata = getOTAMetadata;
|
|
14
14
|
async function resetOTAMetadata() {
|
|
15
|
-
return
|
|
15
|
+
return NativeReactNativeOta_1.default.resetMetadata();
|
|
16
16
|
}
|
|
17
17
|
exports.resetOTAMetadata = resetOTAMetadata;
|
|
18
18
|
async function getOTADirectory() {
|
|
19
|
-
return
|
|
19
|
+
return NativeReactNativeOta_1.default.getOTADirectory();
|
|
20
20
|
}
|
|
21
21
|
exports.getOTADirectory = getOTADirectory;
|
|
22
22
|
async function prepareManualInstall(bundleVersion) {
|
|
23
|
-
return
|
|
23
|
+
return NativeReactNativeOta_1.default.prepareManualInstall(bundleVersion);
|
|
24
24
|
}
|
|
25
25
|
exports.prepareManualInstall = prepareManualInstall;
|
|
26
26
|
async function markOTASuccess() {
|
|
27
|
-
return
|
|
27
|
+
return NativeReactNativeOta_1.default.markSuccess();
|
|
28
28
|
}
|
|
29
29
|
exports.markOTASuccess = markOTASuccess;
|
|
30
30
|
async function copyBundleFromDocuments(bundleVersion, fileName) {
|
|
31
31
|
if (react_native_1.Platform.OS !== 'ios') {
|
|
32
32
|
return false;
|
|
33
33
|
}
|
|
34
|
-
return
|
|
34
|
+
return NativeReactNativeOta_1.default.copyBundleFromDocuments(bundleVersion, fileName);
|
|
35
35
|
}
|
|
36
36
|
exports.copyBundleFromDocuments = copyBundleFromDocuments;
|
|
37
37
|
async function getCurrentBundleInfo() {
|
|
38
|
-
const bundleInfo = await
|
|
38
|
+
const bundleInfo = await NativeReactNativeOta_1.default.getCurrentBundleInfo();
|
|
39
39
|
return JSON.parse(bundleInfo);
|
|
40
40
|
}
|
|
41
41
|
exports.getCurrentBundleInfo = getCurrentBundleInfo;
|
|
42
42
|
async function downloadAndInstallBundle(update) {
|
|
43
|
-
return
|
|
43
|
+
return NativeReactNativeOta_1.default.downloadAndInstallBundle(JSON.stringify(update));
|
|
44
44
|
}
|
|
45
45
|
exports.downloadAndInstallBundle = downloadAndInstallBundle;
|
|
46
46
|
async function getDownloadInfo(version) {
|
|
47
|
-
const downloadInfo = await
|
|
47
|
+
const downloadInfo = await NativeReactNativeOta_1.default.getDownloadInfo(version);
|
|
48
48
|
return JSON.parse(downloadInfo);
|
|
49
49
|
}
|
|
50
50
|
exports.getDownloadInfo = getDownloadInfo;
|
|
51
51
|
async function getOTADiskUsage() {
|
|
52
|
-
const diskUsage = await
|
|
52
|
+
const diskUsage = await NativeReactNativeOta_1.default.getOTADiskUsage();
|
|
53
53
|
return JSON.parse(diskUsage);
|
|
54
54
|
}
|
|
55
55
|
exports.getOTADiskUsage = getOTADiskUsage;
|
|
56
56
|
async function cleanupOTAStorage() {
|
|
57
|
-
return
|
|
57
|
+
return NativeReactNativeOta_1.default.cleanupOTAStorage();
|
|
58
58
|
}
|
|
59
59
|
exports.cleanupOTAStorage = cleanupOTAStorage;
|
package/package.json
CHANGED
package/react-native-ota.podspec
CHANGED
package/src/NativeOTAUpdate.ts
CHANGED
|
File without changes
|
|
File without changes
|
|
File without changes
|