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

Commit ae72dd0

Browse files
committed
merge syncstatus and syncresult
1 parent 7be3159 commit ae72dd0

File tree

3 files changed

+66
-37
lines changed

3 files changed

+66
-37
lines changed

CodePush.ios.js

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,25 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
158158
case CodePush.SyncStatus.INSTALLING_UPDATE:
159159
log("Installing update.");
160160
break;
161-
case CodePush.SyncStatus.IDLE:
162-
log("Sync is idle.");
161+
case CodePush.SyncStatus.UP_TO_DATE:
162+
log("App is up to date.");
163+
break;
164+
case CodePush.SyncStatus.UPDATE_IGNORED:
165+
log("User cancelled the update.");
166+
break;
167+
case CodePush.SyncStatus.UPDATE_INSTALLED:
168+
/*
169+
* If the install mode is IMMEDIATE, this will not get returned as the
170+
* app will be restarted to a new Javascript context.
171+
*/
172+
if (syncOptions.installMode == CodePush.InstallMode.ON_NEXT_RESTART) {
173+
log("Update is installed and will be run on the next app restart.");
174+
} else {
175+
log("Update is installed and will be run when the app next resumes.");
176+
}
177+
break;
178+
case CodePush.SyncStatus.UNKNOWN_ERROR:
179+
log("An unknown error occurred.");
163180
break;
164181
}
165182
};
@@ -182,16 +199,16 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
182199
return localPackage.install(syncOptions.rollbackTimeout, syncOptions.installMode)
183200
})
184201
.then(() => {
185-
syncStatusChangeCallback(CodePush.SyncStatus.IDLE);
186-
resolve(CodePush.SyncResult.UPDATE_INSTALLED)
202+
syncStatusChangeCallback(CodePush.SyncStatus.UPDATE_INSTALLED);
203+
resolve(CodePush.SyncStatus.UPDATE_INSTALLED)
187204
})
188205
.catch(reject)
189206
.done();
190207
}
191208

192209
if (!remotePackage || (remotePackage.failedInstall && syncOptions.ignoreFailedUpdates)) {
193-
syncStatusChangeCallback(CodePush.SyncStatus.IDLE);
194-
resolve(CodePush.SyncResult.UP_TO_DATE);
210+
syncStatusChangeCallback(CodePush.SyncStatus.UP_TO_DATE);
211+
resolve(CodePush.SyncStatus.UP_TO_DATE);
195212
}
196213
else if (syncOptions.updateDialog) {
197214
syncOptions.updateDialog = Object.assign(CodePush.DEFAULT_UPDATE_DIALOG, syncOptions.updateDialog);
@@ -217,7 +234,7 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
217234
// to allow the end-user to ignore it
218235
dialogButtons.push({
219236
text: syncOptions.updateDialog.optionalIgnoreButtonLabel,
220-
onPress: () => resolve(CodePush.SyncResult.UPDATE_IGNORED)
237+
onPress: () => resolve(CodePush.SyncStatus.UPDATE_IGNORED)
221238
});
222239
}
223240

@@ -233,7 +250,10 @@ function sync(options = {}, syncStatusChangeCallback, downloadProgressCallback)
233250
doDownloadAndInstall();
234251
}
235252
})
236-
.catch(reject)
253+
.catch((error) => {
254+
syncStatusChangeCallback(CodePush.SyncStatus.UNKNOWN_ERROR);
255+
reject(error);
256+
})
237257
.done();
238258
});
239259
};
@@ -242,6 +262,7 @@ var CodePush = {
242262
checkForUpdate: checkForUpdate,
243263
getConfiguration: getConfiguration,
244264
getCurrentPackage: getCurrentPackage,
265+
log: log,
245266
notifyApplicationReady: NativeCodePush.notifyApplicationReady,
246267
setUpTestDependencies: setUpTestDependencies,
247268
sync: sync,
@@ -250,17 +271,15 @@ var CodePush = {
250271
ON_NEXT_RESTART: NativeCodePush.codePushInstallModeOnNextRestart, // Don't artificially restart the app. Allow the update to be "picked up" on the next app restart
251272
ON_NEXT_RESUME: NativeCodePush.codePushInstallModeOnNextResume // Restart the app the next time it is resumed from the background
252273
},
253-
SyncResult: {
254-
UP_TO_DATE: 0, // The running app is up-to-date
255-
UPDATE_IGNORED: 1, // The app had an optional update and the end-user chose to ignore it
256-
UPDATE_INSTALLED: 2 // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
257-
},
258274
SyncStatus: {
259275
CHECKING_FOR_UPDATE: 0,
260276
AWAITING_USER_ACTION: 1,
261277
DOWNLOADING_PACKAGE: 2,
262278
INSTALLING_UPDATE: 3,
263-
IDLE: 4
279+
UP_TO_DATE: 4, // The running app is up-to-date
280+
UPDATE_IGNORED: 5, // The app had an optional update and the end-user chose to ignore it
281+
UPDATE_INSTALLED: 6, // The app had an optional/mandatory update that was successfully downloaded and is about to be installed.
282+
UNKNOWN_ERROR: -1
264283
},
265284
DEFAULT_UPDATE_DIALOG: {
266285
appendReleaseDescription: false,

Examples/CodePushDemoApp/index.ios.js

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,39 @@ var CodePushDemoApp = React.createClass({
5050
syncMessage: "Installing update."
5151
});
5252
break;
53-
case CodePush.SyncStatus.IDLE:
53+
case CodePush.SyncStatus.UP_TO_DATE:
54+
self.setState({
55+
syncMessage: "App up to date.",
56+
progress: false
57+
});
58+
break;
59+
case CodePush.SyncStatus.UPDATE_IGNORED:
60+
self.setState({
61+
syncMessage: "Update cancelled by user.",
62+
progress: false
63+
});
64+
break;
65+
case CodePush.SyncStatus.UPDATE_INSTALLED:
5466
self.setState({
5567
syncMessage: "Update installed and will be run when the app next resumes.",
5668
progress: false
5769
});
5870
break;
71+
case CodePush.SyncStatus.UNKNOWN_ERROR:
72+
self.setState({
73+
syncMessage: "An unknown error occurred.",
74+
progress: false
75+
});
76+
break;
5977
}
6078
},
6179
function(progress) {
6280
self.setState({
6381
progress: progress
6482
});
6583
}
66-
).then(function(syncResult) {
67-
switch(syncResult) {
68-
case CodePush.SyncResult.UP_TO_DATE:
69-
self.setState({
70-
syncMessage: "App up to date."
71-
});
72-
break;
73-
case CodePush.SyncResult.UPDATE_IGNORED:
74-
self.setState({
75-
syncMessage: "Update cancelled by user."
76-
});
77-
break;
78-
}
84+
).catch(function(error) {
85+
CodePush.log(error);
7986
});
8087
},
8188
getInitialState: function() {

README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ If the `rollbackTimeout` parameter was not specified, the CodePush runtime will
175175
#### codePush.sync
176176

177177
```javascript
178-
codePush.sync(options: Object, onSyncStatusChange: function(syncStatus: Number), onDownloadProgress: function(progress: DownloadProgress)): Promise<Number>;
178+
codePush.sync(options: Object, syncStatusChangeCallback: function(syncStatus: Number), downloadProgressCallback: function(progress: DownloadProgress)): Promise<Number>;
179179
```
180180

181181
Provides a simple option for checking for an update, displaying a notification to the user, downloading it and then installing it, all while also respecting the policy that your release was published with. This method effectively composes together the "advanced mode" APIs for you, so that you don't need to handle any of the following scenarios yourself:
@@ -204,22 +204,25 @@ The method accepts an options object that allows you to customize numerous aspec
204204

205205
In addition, the method also recieves two function arguments which serve as event handlers which are called at various points in the sync process:
206206

207-
* __onSyncStatusChange__ (function(syncStatus: Number)) - Called when the sync process moves to a different step. Below is the list of possible SyncStatus values:
207+
* __syncStatusChangeCallback__ (function(syncStatus: Number)) - Called when the sync process moves to a different step. Below is the list of possible SyncStatus values:
208208
* __CodePush.SyncStatus.CHECKING_FOR_UPDATE__ *(0)* - Querying the CodePush server for an update.
209209
* __CodePush.SyncStatus.AWAITING_USER_ACTION__ *(1)* - Waiting for a response from the user (e.g. a confirmation dialog).
210210
* __CodePush.SyncStatus.DOWNLOADING_PACKAGE__ *(2)* - Downloading the updated package from the CodePush server.
211-
* __CodePush.SyncStatus.INSTALLING_UPDATE__ *(3)* - Installing the downloaded update package.
212-
* __CodePush.SyncStatus.IDLE__ *(4)* - The sync process has exited and is now idling.
211+
* __CodePush.SyncStatus.INSTALLING_UPDATE__ *(3)* - The app had an optional or mandatory update that was successfully downloaded and is about to be installed.
212+
* __CodePush.SyncStatus.UP_TO_DATE__ *(4)* - The app does not have an available update.
213+
* __CodePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app has an optional update, that the user chose to ignore.
214+
* __CodePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - The update has been installed and will be run the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
215+
* __CodePush.SyncStatus.UNKNOWN_ERROR__ *(-1)* - The sync operation encountered an unknown error.
213216

214-
* __onDownloadProgress__ (function(progress: DownloadProgress)) - Called periodically when the update package is being downloaded from the CodePush server to report the progress of the update. `DownloadProgress` contains two fields:
217+
* __downloadProgressCallback__ (function(progress: DownloadProgress)) - Called periodically when the update package is being downloaded from the CodePush server to report the progress of the update. `DownloadProgress` contains two fields:
215218
* __totalBytes__ (Number) - The total number of bytes expected to be received for this update package
216219
* __receivedBytes__ (Number) - The number of bytes downloaded thus far.
217220

218-
The method returns a `Promise` that is resolved to a `SyncResult` integer code, which indicates why the `sync` call succeeded. This code can be one of the following values:
221+
The method returns a `Promise` that is resolved to a `SyncStatus` integer code, which indicates why the `sync` call succeeded. This code can be one of the following values:
219222

220-
* __CodePush.SyncResult.UP_TO_DATE__ *(0)* - The app doesn't have an available update.
221-
* __CodePush.SyncResult.UPDATE_IGNORED__ *(1)* - The app has an optional update, that the user chose to ignore.
222-
* __CodePush.SyncResult.UPDATE_INSTALLED__ *(2)* - The app had an optional or mandatory update that was successfully downloaded and is about to be installed. If your app needs to do any data persistence/migration before restarting, this is the time to do it.
223+
* __CodePush.SyncStatus.UP_TO_DATE__ *(4)* - The app does not have an available update.
224+
* __CodePush.SyncStatus.UPDATE_IGNORED__ *(5)* - The app has an optional update, that the user chose to ignore.
225+
* __CodePush.SyncStatus.UPDATE_INSTALLED__ *(6)* - The update has been installed and will be run the next time the app resumes/restarts, depending on the `InstallMode` specified in `SyncOptions`.
223226

224227
If the update check and/or the subseqeuent download fails for any reason, the `Promise` object returned by `sync` will be rejected with the reason.
225228

0 commit comments

Comments
 (0)