Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 3594c0b

Browse files
committed
Merge pull request #72 from Microsoft/restart_change
Renaming restartPendingUpdate to restartApp
2 parents c4b96ed + 3378f6f commit 3594c0b

File tree

5 files changed

+9
-60
lines changed

5 files changed

+9
-60
lines changed

CodePush.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ var CodePush = {
267267
getCurrentPackage: getCurrentPackage,
268268
log: log,
269269
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
270-
restartPendingUpdate: NativeCodePush.restartPendingUpdate,
270+
restartApp: NativeCodePush.restartApp,
271271
setUpTestDependencies: setUpTestDependencies,
272272
sync: sync,
273273
InstallMode: {

CodePush.m

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -394,35 +394,13 @@ - (void)startRollbackTimer:(int)rollbackTimeout
394394
}
395395

396396
/*
397-
* This method isn't publicly exposed via the "react-native-code-push"
398-
* module, and is only used internally to support immediately installed updates.
397+
* This method is the native side of the CodePush.restartApp() method.
399398
*/
400-
RCT_EXPORT_METHOD(restartImmediateUpdate:(int)rollbackTimeout)
399+
RCT_EXPORT_METHOD(restartApp)
401400
{
402401
[self loadBundle];
403402
}
404403

405-
/*
406-
* This method is the native side of the CodePush.restartPendingUpdate() method.
407-
*/
408-
RCT_EXPORT_METHOD(restartPendingUpdate)
409-
{
410-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
411-
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
412-
NSDictionary *pendingUpdate = [preferences objectForKey:PendingUpdateKey];
413-
414-
if (pendingUpdate) {
415-
NSError *error;
416-
NSString *pendingHash = pendingUpdate[PendingUpdateHashKey];
417-
NSString *currentHash = [CodePushPackage getCurrentPackageHash:&error];
418-
419-
NSAssert([pendingHash isEqualToString:currentHash], @"There is a pending update but it's hash doesn't match that of the current package.");
420-
421-
[self loadBundle];
422-
}
423-
});
424-
}
425-
426404
RCT_EXPORT_METHOD(setUsingTestFolder:(BOOL)shouldUseTestFolder)
427405
{
428406
usingTestFolder = shouldUseTestFolder;

README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ When you require `react-native-code-push`, the module object provides the follow
191191
192192
* [notifyApplicationReady](#codepushnotifyapplicationready): Notifies the CodePush runtime that an installed update is considered successful. This is an optional API, but is useful when you want to expicitly enable "rollback protection" in the event that an exception occurs in code that you've deployed to production.
193193
194-
* [restartPendingUpdate](#codepushrestartPendingUpdate): Conditionally restarts the app if a previously installed update is currently pending (e.g. it was installed using the `ON_NEXT_RESTART` or `ON_NEXT_RESUME` modes, and the app hasn't been restarted or resumed yet).
194+
* [restartApp](#codepushrestartapp): Immediately restarts the app. If there is an update pending, it will be immediately displayed to the end-user, and the rollback timer (if specified when installing the update) will begin. Otherwise, calling this method simply has the same behavior as the end-user killing and restarting the process.
195195
196196
* [sync](#codepushsync): Allows checking for an update, downloading it and installing it, all with a single call. Unless you need custom UI and/or behavior, we recommend most developers to use this method when integrating CodePush into their apps
197197
@@ -255,18 +255,16 @@ Notifies the CodePush runtime that an update should be considered successful, an
255255

256256
If the `rollbackTimeout` parameter was not specified, the CodePush runtime will not enforce any automatic rollback behavior, and therefore, calling this function is not required and will result in a no-op.
257257

258-
### codePush.restartPendingUpdate
258+
### codePush.restartApp
259259
260260
```javascript
261-
codePush.restartPendingUpdate(): void;
261+
codePush.restartApp(): void;
262262
```
263263
264-
Applies the pending update (if applicable) by immediately restarting the app, and optionally starting the rollback timer. This method is for advanced scenarios, and is only useful when the following conditions are true:
264+
Immediately restarts the app. If there is an update pending, it will be presented to the end-user and the rollback timer (if specified when installing the update) will begin. Otherwise, calling this method simply has the same behavior as the end-user killing and restarting the process. This method is for advanced scenarios, and is primarily useful when the following conditions are true:
265265

266266
1. Your app is specifying an install mode value of `ON_NEXT_RESTART` or `ON_NEXT_RESUME` when calling the `sync` or `LocalPackage.install` methods. This has the effect of not applying your update until the app has been restarted (by either the end-user or OS) or resumed, and therefore, the update won't be immediately displayed to the end-user .
267267
2. You have an app-specific user event (e.g. the end-user navigated back to the app's home route) that allows you to apply the update in an unobtrusive way, and potentially gets the update in front of the end-user sooner then waiting until the next restart or resume.
268-
269-
If you call this method, and there isn't a pending update, it will result in a no-op. Otherwise, the app will be restarted in order to display the update to the end-user.
270268

271269
### codePush.sync
272270

android/app/src/main/java/com/microsoft/codepush/react/CodePush.java

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -376,37 +376,10 @@ public void setUsingTestFolder(boolean shouldUseTestFolder) {
376376
}
377377

378378
@ReactMethod
379-
public void restartImmediateUpdate(int rollbackTimeout) {
379+
public void restartApp() {
380380
loadBundle();
381381
}
382382

383-
@ReactMethod
384-
public void restartPendingUpdate() {
385-
SharedPreferences settings = applicationContext.getSharedPreferences(CODE_PUSH_PREFERENCES, 0);
386-
String pendingUpdateString = settings.getString(PENDING_UPDATE_KEY, null);
387-
388-
if (pendingUpdateString != null) {
389-
try {
390-
JSONObject pendingUpdateJSON = new JSONObject(pendingUpdateString);
391-
String pendingHash = pendingUpdateJSON.getString(PENDING_UPDATE_HASH_KEY);
392-
String currentHash = codePushPackage.getCurrentPackageHash();
393-
if (!pendingHash.equals(currentHash)) {
394-
throw new CodePushUnknownException("Pending hash " + pendingHash +
395-
" and current hash " + currentHash + " are different");
396-
}
397-
398-
loadBundle();
399-
} catch (JSONException e) {
400-
// Should not happen.
401-
throw new CodePushUnknownException("Unable to parse pending update metadata " +
402-
pendingUpdateString + " stored in SharedPreferences", e);
403-
} catch (IOException e) {
404-
// There is no current package hash.
405-
throw new CodePushUnknownException("Should not register a pending update without a saving a current package", e);
406-
}
407-
}
408-
}
409-
410383
@Override
411384
public Map<String, Object> getConstants() {
412385
final Map<String, Object> constants = new HashMap<>();

package-mixins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = (NativeCodePush) => {
4141
.then(function() {
4242
updateInstalledCallback && updateInstalledCallback();
4343
if (installMode == NativeCodePush.codePushInstallModeImmediate) {
44-
NativeCodePush.restartImmediateUpdate(rollbackTimeout);
44+
NativeCodePush.restartApp();
4545
};
4646
});
4747
}

0 commit comments

Comments
 (0)