react-native-update 10.38.0-beta.2 → 10.38.0-beta.3
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.
|
@@ -26,12 +26,14 @@ public class UpdateContext {
|
|
|
26
26
|
public static boolean DEBUG = true;
|
|
27
27
|
private static ReactInstanceManager mReactInstanceManager;
|
|
28
28
|
private static boolean isUsingBundleUrl = false;
|
|
29
|
+
private static boolean ignoreRollback = false;
|
|
29
30
|
private static final int STATE_OP_SWITCH_VERSION = 1;
|
|
30
31
|
private static final int STATE_OP_MARK_SUCCESS = 2;
|
|
31
32
|
private static final int STATE_OP_ROLLBACK = 3;
|
|
32
33
|
private static final int STATE_OP_CLEAR_FIRST_TIME = 4;
|
|
33
34
|
private static final int STATE_OP_CLEAR_ROLLBACK_MARK = 5;
|
|
34
35
|
private static final int STATE_OP_RESOLVE_LAUNCH = 6;
|
|
36
|
+
private static final String KEY_FIRST_LOAD_MARKED = "firstLoadMarked";
|
|
35
37
|
|
|
36
38
|
// Singleton instance
|
|
37
39
|
private static UpdateContext sInstance;
|
|
@@ -77,7 +79,7 @@ public class UpdateContext {
|
|
|
77
79
|
SharedPreferences.Editor editor = this.sp.edit();
|
|
78
80
|
editor.clear();
|
|
79
81
|
applyState(editor, nextState);
|
|
80
|
-
editor
|
|
82
|
+
persistEditor(editor, "sync state with binary version");
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
|
|
@@ -199,6 +201,12 @@ public class UpdateContext {
|
|
|
199
201
|
putNullableString(editor, "rolledBackVersion", state.rolledBackVersion);
|
|
200
202
|
}
|
|
201
203
|
|
|
204
|
+
private void persistEditor(SharedPreferences.Editor editor, String reason) {
|
|
205
|
+
if (!editor.commit() && DEBUG) {
|
|
206
|
+
Log.w("react-native-update", "Failed to persist update state for " + reason);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
202
210
|
public void switchVersion(String hash) {
|
|
203
211
|
if (!new File(rootDir, hash+"/index.bundlejs").exists()) {
|
|
204
212
|
throw new Error("Bundle version " + hash + " not found.");
|
|
@@ -214,13 +222,14 @@ public class UpdateContext {
|
|
|
214
222
|
);
|
|
215
223
|
SharedPreferences.Editor editor = sp.edit();
|
|
216
224
|
applyState(editor, nextState);
|
|
217
|
-
editor
|
|
225
|
+
persistEditor(editor, "switch version");
|
|
226
|
+
ignoreRollback = false;
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
public void setKv(String key, String value) {
|
|
221
230
|
SharedPreferences.Editor editor = sp.edit();
|
|
222
231
|
editor.putString(key, value);
|
|
223
|
-
editor
|
|
232
|
+
persistEditor(editor, "set key " + key);
|
|
224
233
|
}
|
|
225
234
|
|
|
226
235
|
public String getKv(String key) {
|
|
@@ -235,6 +244,16 @@ public class UpdateContext {
|
|
|
235
244
|
return sp.getBoolean("firstTime", false);
|
|
236
245
|
}
|
|
237
246
|
|
|
247
|
+
public boolean consumeFirstLoadMarker() {
|
|
248
|
+
boolean isFirstLoadMarked = sp.getBoolean(KEY_FIRST_LOAD_MARKED, false);
|
|
249
|
+
if (isFirstLoadMarked) {
|
|
250
|
+
SharedPreferences.Editor editor = sp.edit();
|
|
251
|
+
editor.remove(KEY_FIRST_LOAD_MARKED);
|
|
252
|
+
persistEditor(editor, "clear first load marker");
|
|
253
|
+
}
|
|
254
|
+
return isFirstLoadMarked;
|
|
255
|
+
}
|
|
256
|
+
|
|
238
257
|
public String rolledBackVersion() {
|
|
239
258
|
return sp.getString("rolledBackVersion", null);
|
|
240
259
|
}
|
|
@@ -254,7 +273,7 @@ public class UpdateContext {
|
|
|
254
273
|
if (nextState.staleVersionToDelete != null) {
|
|
255
274
|
editor.remove("hash_" + nextState.staleVersionToDelete);
|
|
256
275
|
}
|
|
257
|
-
editor
|
|
276
|
+
persistEditor(editor, "mark success");
|
|
258
277
|
|
|
259
278
|
this.cleanUp();
|
|
260
279
|
}
|
|
@@ -271,7 +290,8 @@ public class UpdateContext {
|
|
|
271
290
|
);
|
|
272
291
|
SharedPreferences.Editor editor = sp.edit();
|
|
273
292
|
applyState(editor, nextState);
|
|
274
|
-
editor.
|
|
293
|
+
editor.remove(KEY_FIRST_LOAD_MARKED);
|
|
294
|
+
persistEditor(editor, "clear first time");
|
|
275
295
|
|
|
276
296
|
this.cleanUp();
|
|
277
297
|
}
|
|
@@ -287,7 +307,7 @@ public class UpdateContext {
|
|
|
287
307
|
);
|
|
288
308
|
SharedPreferences.Editor editor = sp.edit();
|
|
289
309
|
applyState(editor, nextState);
|
|
290
|
-
editor
|
|
310
|
+
persistEditor(editor, "clear rollback mark");
|
|
291
311
|
|
|
292
312
|
this.cleanUp();
|
|
293
313
|
}
|
|
@@ -334,13 +354,20 @@ public class UpdateContext {
|
|
|
334
354
|
STATE_OP_RESOLVE_LAUNCH,
|
|
335
355
|
currentState,
|
|
336
356
|
null,
|
|
337
|
-
|
|
338
|
-
|
|
357
|
+
ignoreRollback,
|
|
358
|
+
true
|
|
339
359
|
);
|
|
340
360
|
if (launchState.didRollback || launchState.consumedFirstTime) {
|
|
341
361
|
SharedPreferences.Editor editor = sp.edit();
|
|
342
362
|
applyState(editor, launchState);
|
|
343
|
-
|
|
363
|
+
if (launchState.consumedFirstTime) {
|
|
364
|
+
editor.putBoolean(KEY_FIRST_LOAD_MARKED, true);
|
|
365
|
+
}
|
|
366
|
+
persistEditor(editor, "resolve launch");
|
|
367
|
+
}
|
|
368
|
+
if (launchState.consumedFirstTime) {
|
|
369
|
+
// bundleURL may be resolved multiple times in one process.
|
|
370
|
+
ignoreRollback = true;
|
|
344
371
|
}
|
|
345
372
|
|
|
346
373
|
String currentVersion = launchState.loadVersion;
|
|
@@ -372,7 +399,7 @@ public class UpdateContext {
|
|
|
372
399
|
);
|
|
373
400
|
SharedPreferences.Editor editor = sp.edit();
|
|
374
401
|
applyState(editor, nextState);
|
|
375
|
-
editor
|
|
402
|
+
persistEditor(editor, "rollback");
|
|
376
403
|
return nextState.currentVersion;
|
|
377
404
|
}
|
|
378
405
|
|
|
@@ -37,11 +37,8 @@ public class UpdateModule extends NativePushySpec {
|
|
|
37
37
|
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
|
|
38
38
|
constants.put("buildTime", updateContext.getBuildTime());
|
|
39
39
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
|
40
|
-
boolean isFirstTime = updateContext.
|
|
40
|
+
boolean isFirstTime = updateContext.consumeFirstLoadMarker();
|
|
41
41
|
constants.put("isFirstTime", isFirstTime);
|
|
42
|
-
if (isFirstTime) {
|
|
43
|
-
updateContext.clearFirstTime();
|
|
44
|
-
}
|
|
45
42
|
String rolledBackVersion = updateContext.rolledBackVersion();
|
|
46
43
|
constants.put("rolledBackVersion", rolledBackVersion);
|
|
47
44
|
if (rolledBackVersion != null) {
|
|
@@ -53,11 +53,8 @@ public class UpdateModule extends ReactContextBaseJavaModule {
|
|
|
53
53
|
constants.put("currentVersionInfo", updateContext.getKv("hash_" + currentVersion));
|
|
54
54
|
constants.put("buildTime", updateContext.getBuildTime());
|
|
55
55
|
constants.put("isUsingBundleUrl", updateContext.getIsUsingBundleUrl());
|
|
56
|
-
boolean isFirstTime = updateContext.
|
|
56
|
+
boolean isFirstTime = updateContext.consumeFirstLoadMarker();
|
|
57
57
|
constants.put("isFirstTime", isFirstTime);
|
|
58
|
-
if (isFirstTime) {
|
|
59
|
-
updateContext.clearFirstTime();
|
|
60
|
-
}
|
|
61
58
|
String rolledBackVersion = updateContext.rolledBackVersion();
|
|
62
59
|
constants.put("rolledBackVersion", rolledBackVersion);
|
|
63
60
|
if (rolledBackVersion != null) {
|