@@ -97,34 +97,57 @@ function notifyApplicationReady() {
97
97
}
98
98
99
99
function sync ( options = { } ) {
100
+ var syncOptions = {
101
+ ignoreFailedUpdates : true ,
102
+
103
+ mandatoryContinueButtonLabel : "Continue" ,
104
+ mandatoryUpdateMessage : "An update is available that must be installed" ,
105
+
106
+ optionalIgnoreButtonLabel : "Ignore" ,
107
+ optionalInstallButtonLabel : "Install" ,
108
+ optionalUpdateMessage : "An update is available. Would you like to install it?" ,
109
+
110
+ updateTitle : "Update available" ,
111
+ rollbackTimeout : 0 ,
112
+
113
+ ...options
114
+ } ;
115
+
100
116
return new Promise ( ( resolve , reject ) => {
101
117
checkForUpdate ( )
102
118
. then ( ( remotePackage ) => {
103
- if ( ! remotePackage ) {
119
+ if ( ! remotePackage || ( remotePackage . failedAppy && syncOptions . ignoreFailedUpdates ) ) {
104
120
resolve ( CodePush . SyncStatus . NO_UPDATE_AVAILABLE ) ;
105
121
}
106
122
else {
123
+ var message = null ;
107
124
var dialogButtons = [
108
125
{
109
- text : options . updateButtonText || "Update" ,
126
+ text : null ,
110
127
onPress : ( ) => {
111
128
remotePackage . download ( )
112
129
. then ( ( localPackage ) => {
113
130
resolve ( CodePush . SyncStatus . APPLY_SUCCESS ) ;
114
- localPackage . apply ( options . rollbackTimeout ) ;
131
+ localPackage . apply ( syncOptions . rollbackTimeout ) ;
115
132
} , reject ) ;
116
133
}
117
134
}
118
135
] ;
119
136
120
- if ( ! remotePackage . isMandatory ) {
137
+ if ( remotePackage . isMandatory ) {
138
+ message = syncOptions . mandatoryUpdateMessage ;
139
+ dialogButtons [ 0 ] . text = syncOptions . mandatoryContinueButtonLabel ;
140
+ } else {
141
+ message = syncOptions . optionalUpdateMessage ;
142
+
143
+ dialogButtons [ 0 ] . text = syncOptions . optionalInstallButtonLabel ;
121
144
dialogButtons . push ( {
122
- text : options . ignoreButtonText || "Ignore" ,
145
+ text : syncOptions . optionalIgnoreButtonLabel ,
123
146
onPress : ( ) => resolve ( CodePush . SyncStatus . UPDATE_IGNORED )
124
147
} ) ;
125
148
}
126
149
127
- AlertIOS . alert ( options . updateTitle || "Update available" , remotePackage . description , dialogButtons ) ;
150
+ AlertIOS . alert ( syncOptions . updateTitle , message || remotePackage . description , dialogButtons ) ;
128
151
}
129
152
} , reject ) ;
130
153
} ) ;
0 commit comments