react-native-ota-hot-update 1.1.9 → 1.2.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.
|
@@ -219,6 +219,24 @@ public class HotUpdateModule extends ReactContextBaseJavaModule {
|
|
|
219
219
|
promise.resolve(true);
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
@ReactMethod
|
|
223
|
+
public void getUpdateMetadata(Promise promise) {
|
|
224
|
+
SharedPrefs sharedPrefs = new SharedPrefs(getReactApplicationContext());
|
|
225
|
+
String metadata = sharedPrefs.getString(Common.INSTANCE.getMETADATA());
|
|
226
|
+
if (!metadata.equals("")) {
|
|
227
|
+
promise.resolve(metadata);
|
|
228
|
+
} else {
|
|
229
|
+
promise.resolve(null);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
@ReactMethod
|
|
234
|
+
public void setUpdateMetadata(String metadataString, Promise promise) {
|
|
235
|
+
SharedPrefs sharedPrefs = new SharedPrefs(getReactApplicationContext());
|
|
236
|
+
sharedPrefs.putString(Common.INSTANCE.getMETADATA(), metadataString);
|
|
237
|
+
promise.resolve(true);
|
|
238
|
+
}
|
|
239
|
+
|
|
222
240
|
@NonNull
|
|
223
241
|
@Override
|
|
224
242
|
public String getName() {
|
package/ios/RNhotupdate.m
CHANGED
|
@@ -291,6 +291,28 @@ RCT_EXPORT_METHOD(setExactBundlePath:(NSString *)path
|
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
|
|
294
|
+
RCT_EXPORT_METHOD(setUpdateMetadata:(NSString *)metadataString withResolver:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
295
|
+
if (metadataString) {
|
|
296
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
297
|
+
[defaults setObject:metadataString forKey:@"METADATA"];
|
|
298
|
+
[defaults synchronize];
|
|
299
|
+
resolve(@(YES));
|
|
300
|
+
} else {
|
|
301
|
+
resolve(@(NO));
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
RCT_EXPORT_METHOD(getUpdateMetadata:(RCTPromiseResolveBlock)resolve withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
306
|
+
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
307
|
+
NSString *metadata = [defaults stringForKey:@"METADATA"];
|
|
308
|
+
|
|
309
|
+
if (metadata) {
|
|
310
|
+
resolve(metadata);
|
|
311
|
+
} else {
|
|
312
|
+
resolve(nil);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
294
316
|
- (void)loadBundle
|
|
295
317
|
{
|
|
296
318
|
RCTTriggerReloadCommandListeners(@"rn-hotupdate: Restart");
|
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -46,6 +46,17 @@ function deleteBundlePath(): Promise<boolean> {
|
|
|
46
46
|
function getCurrentVersion(): Promise<string> {
|
|
47
47
|
return RNhotupdate.getCurrentVersion();
|
|
48
48
|
}
|
|
49
|
+
function getUpdateMetadata(): Promise<object | null> {
|
|
50
|
+
return RNhotupdate.getUpdateMetadata()
|
|
51
|
+
.then((metadataString: string | null) => {
|
|
52
|
+
try {
|
|
53
|
+
return metadataString ? JSON.parse(metadataString) : null;
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error('Error parsing metadata:', error);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
49
60
|
function rollbackToPreviousBundle(): Promise<boolean> {
|
|
50
61
|
return RNhotupdate.rollbackToPreviousBundle();
|
|
51
62
|
}
|
|
@@ -56,6 +67,14 @@ async function getVersionAsNumber() {
|
|
|
56
67
|
function setCurrentVersion(version: number): Promise<boolean> {
|
|
57
68
|
return RNhotupdate.setCurrentVersion(version + '');
|
|
58
69
|
}
|
|
70
|
+
function setUpdateMetadata(metadata: any): Promise<boolean> {
|
|
71
|
+
try {
|
|
72
|
+
const metadataString = JSON.stringify(metadata);
|
|
73
|
+
return RNhotupdate.setUpdateMetadata(metadataString);
|
|
74
|
+
} catch (error) {
|
|
75
|
+
console.error('Error stringifying metadata:', error);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
59
78
|
async function resetApp() {
|
|
60
79
|
RNhotupdate.restart();
|
|
61
80
|
}
|
|
@@ -95,6 +114,10 @@ async function downloadBundleUri(downloadManager: DownloadManager, uri: string,
|
|
|
95
114
|
setupBundlePath(path, option?.extensionBundle).then(success => {
|
|
96
115
|
if (success) {
|
|
97
116
|
setCurrentVersion(version);
|
|
117
|
+
|
|
118
|
+
if (option?.metadata) {
|
|
119
|
+
setUpdateMetadata(option.metadata);
|
|
120
|
+
}
|
|
98
121
|
option?.updateSuccess?.();
|
|
99
122
|
if (option?.restartAfterInstall) {
|
|
100
123
|
setTimeout(() => {
|
|
@@ -171,6 +194,8 @@ export default {
|
|
|
171
194
|
resetApp,
|
|
172
195
|
getCurrentVersion: getVersionAsNumber,
|
|
173
196
|
setCurrentVersion,
|
|
197
|
+
getUpdateMetadata,
|
|
198
|
+
setUpdateMetadata,
|
|
174
199
|
rollbackToPreviousBundle,
|
|
175
200
|
git: {
|
|
176
201
|
checkForGitUpdate,
|