4
4
using ReactNative . Modules . Core ;
5
5
using System ;
6
6
using System . Collections . Generic ;
7
+ using System . IO ;
7
8
using System . Reflection ;
8
9
using System . Threading . Tasks ;
9
10
using Windows . Web . Http ;
@@ -12,7 +13,7 @@ namespace CodePush.ReactNative
12
13
{
13
14
internal class CodePushNativeModule : ReactContextNativeModuleBase
14
15
{
15
- private CodePushResumeListener _codePushLifecycleEventListener = null ;
16
+ private CodePushLifecycleEventListener _codePushLifecycleEventListener = null ;
16
17
private ReactContext _reactContext ;
17
18
private CodePushReactPackage _codePush ;
18
19
@@ -36,12 +37,12 @@ public override IReadOnlyDictionary<string, object> Constants
36
37
{
37
38
return new Dictionary < string , object >
38
39
{
39
- { "codePushInstallModeImmediate" , InstallMode . ON_NEXT_RESTART } ,
40
- { "codePushInstallModeOnNextResume" , InstallMode . ON_NEXT_RESUME } ,
41
- { "codePushInstallModeOnNextRestart" , InstallMode . ON_NEXT_RESTART } ,
42
- { "codePushUpdateStateRunning" , UpdateState . RUNNING } ,
43
- { "codePushUpdateStatePending" , UpdateState . PENDING } ,
44
- { "codePushUpdateStateLatest" , UpdateState . LATEST } ,
40
+ { "codePushInstallModeImmediate" , InstallMode . Immediate } ,
41
+ { "codePushInstallModeOnNextResume" , InstallMode . OnNextResume } ,
42
+ { "codePushInstallModeOnNextRestart" , InstallMode . OnNextRestart } ,
43
+ { "codePushUpdateStateRunning" , UpdateState . Running } ,
44
+ { "codePushUpdateStatePending" , UpdateState . Pending } ,
45
+ { "codePushUpdateStateLatest" , UpdateState . Lastest } ,
45
46
} ;
46
47
}
47
48
}
@@ -70,9 +71,12 @@ await _codePush.UpdateManager.DownloadPackage(
70
71
return ;
71
72
}
72
73
73
- var downloadProgress = new JObject ( ) ;
74
- downloadProgress [ "totalBytes" ] = progress . TotalBytesToReceive ;
75
- downloadProgress [ "receivedBytes" ] = progress . BytesReceived ;
74
+ var downloadProgress = new JObject ( )
75
+ {
76
+ { "totalBytes" , progress . TotalBytesToReceive } ,
77
+ { "receivedBytes" , progress . BytesReceived }
78
+ } ;
79
+
76
80
_reactContext
77
81
. GetJavaScriptModule < RCTDeviceEventEmitter > ( )
78
82
. emit ( CodePushConstants . DownloadProgressEventName , downloadProgress ) ;
@@ -83,7 +87,7 @@ await _codePush.UpdateManager.DownloadPackage(
83
87
JObject newPackage = await _codePush . UpdateManager . GetPackage ( ( string ) updatePackage [ CodePushConstants . PackageHashKey ] ) ;
84
88
promise . Resolve ( newPackage ) ;
85
89
}
86
- catch ( CodePushInvalidUpdateException e )
90
+ catch ( InvalidDataException e )
87
91
{
88
92
CodePushUtils . Log ( e . ToString ( ) ) ;
89
93
SettingsManager . SaveFailedUpdate ( updatePackage ) ;
@@ -105,9 +109,9 @@ public void getConfiguration(IPromise promise)
105
109
var config = new JObject
106
110
{
107
111
{ "appVersion" , _codePush . AppVersion } ,
108
- { "deploymentKey" , _codePush . DeploymentKey } ,
109
- { "serverUrl" , CodePushConstants . CodePushServerUrl } ,
110
112
{ "clientUniqueId" , CodePushUtils . GetDeviceId ( ) } ,
113
+ { "deploymentKey" , _codePush . DeploymentKey } ,
114
+ { "serverUrl" , CodePushConstants . CodePushServerUrl }
111
115
} ;
112
116
113
117
// TODO generate binary hash
@@ -136,16 +140,16 @@ public void getUpdateMetadata(int updateState, IPromise promise)
136
140
if ( currentPackage [ CodePushConstants . PackageHashKey ] != null )
137
141
{
138
142
var currentHash = ( string ) currentPackage [ CodePushConstants . PackageHashKey ] ;
139
- currentUpdateIsPending = _codePush . IsPendingUpdate ( currentHash ) ;
143
+ currentUpdateIsPending = SettingsManager . IsPendingUpdate ( currentHash ) ;
140
144
}
141
145
142
- if ( updateState == ( int ) UpdateState . PENDING && ! currentUpdateIsPending )
146
+ if ( updateState == ( int ) UpdateState . Pending && ! currentUpdateIsPending )
143
147
{
144
148
// The caller wanted a pending update
145
149
// but there isn't currently one.
146
150
promise . Resolve ( "" ) ;
147
151
}
148
- else if ( updateState == ( int ) UpdateState . RUNNING && currentUpdateIsPending )
152
+ else if ( updateState == ( int ) UpdateState . Running && currentUpdateIsPending )
149
153
{
150
154
// The caller wants the running update, but the current
151
155
// one is pending, so we need to grab the previous.
@@ -187,15 +191,23 @@ public void installUpdate(JObject updatePackage, int installMode, int minimumBac
187
191
{
188
192
Action installUpdateAction = async ( ) =>
189
193
{
190
- await _codePush . UpdateManager . InstallPackage ( updatePackage , _codePush . IsPendingUpdate ( null ) ) ;
194
+ await _codePush . UpdateManager . InstallPackage ( updatePackage , SettingsManager . IsPendingUpdate ( null ) ) ;
191
195
var pendingHash = ( string ) updatePackage [ CodePushConstants . PackageHashKey ] ;
192
196
SettingsManager . SavePendingUpdate ( pendingHash , /* isLoading */ false ) ;
193
- if ( installMode == ( int ) InstallMode . ON_NEXT_RESUME )
197
+ if ( installMode == ( int ) InstallMode . OnNextResume )
194
198
{
195
199
if ( _codePushLifecycleEventListener == null )
196
200
{
197
201
// Ensure we do not add the listener twice.
198
- _codePushLifecycleEventListener = new CodePushResumeListener ( this , minimumBackgroundDuration ) ;
202
+ Action loadBundleAction = ( ) =>
203
+ {
204
+ Context . RunOnNativeModulesQueueThread ( async ( ) =>
205
+ {
206
+ await LoadBundle ( ) ;
207
+ } ) ;
208
+ } ;
209
+
210
+ _codePushLifecycleEventListener = new CodePushLifecycleEventListener ( loadBundleAction , minimumBackgroundDuration ) ;
199
211
_reactContext . AddLifecycleEventListener ( _codePushLifecycleEventListener ) ;
200
212
}
201
213
else
@@ -213,7 +225,7 @@ public void installUpdate(JObject updatePackage, int installMode, int minimumBac
213
225
[ ReactMethod ]
214
226
public void isFailedUpdate ( string packageHash , IPromise promise )
215
227
{
216
- promise . Resolve ( _codePush . IsFailedHash ( packageHash ) ) ;
228
+ promise . Resolve ( SettingsManager . IsFailedHash ( packageHash ) ) ;
217
229
}
218
230
219
231
[ ReactMethod ]
@@ -245,7 +257,7 @@ public void restartApp(bool onlyIfUpdateIsPending)
245
257
{
246
258
// If this is an unconditional restart request, or there
247
259
// is current pending update, then reload the app.
248
- if ( ! onlyIfUpdateIsPending || _codePush . IsPendingUpdate ( null ) )
260
+ if ( ! onlyIfUpdateIsPending || SettingsManager . IsPendingUpdate ( null ) )
249
261
{
250
262
await LoadBundle ( ) ;
251
263
}
0 commit comments