internal void InitializeUpdateAfterRestart() { // Reset the state which indicates that // the app was just freshly updated. DidUpdate = false; JObject pendingUpdate = SettingsManager.GetPendingUpdate(); if (pendingUpdate != null) { var updateIsLoading = (bool)pendingUpdate[GreatPushConstants.PendingUpdateIsLoadingKey]; if (updateIsLoading) { // Pending update was initialized, but notifyApplicationReady was not called. // Therefore, deduce that it is a broken update and rollback. GreatPushUtils.Log("Update did not finish loading the last time, rolling back to a previous version."); NeedToReportRollback = true; RollbackPackageAsync().Wait(); } else { DidUpdate = true; // Clear the React dev bundle cache so that new updates can be loaded. if (UseDeveloperSupport) { FileUtils.ClearReactDevBundleCacheAsync().Wait(); } // Mark that we tried to initialize the new update, so that if it crashes, // we will know that we need to rollback when the app next starts. SettingsManager.SavePendingUpdate((string)pendingUpdate[GreatPushConstants.PendingUpdateHashKey], /* isLoading */ true); } } }
public GreatPushReactPackage(string deploymentKey, ReactNativeHost host) { AppVersion = GreatPushUtils.GetAppVersion(); DeploymentKey = deploymentKey; Host = host; UpdateManager = new UpdateManager(); if (CurrentInstance != null) { GreatPushUtils.Log("More than one GreatPush instance has been initialized. Please use the instance method greatPush.getBundleUrlInternal() to get the correct bundleURL for a particular instance."); } CurrentInstance = this; }
#pragma warning disable CS0618 // Keeping for backward compatibility public GreatPushReactPackage(string deploymentKey, ReactPage mainPage) #pragma warning restore CS0618 // Keeping for backward compatibility { AppVersion = GreatPushUtils.GetAppVersion(); DeploymentKey = deploymentKey; MainPage = mainPage; UpdateManager = new UpdateManager(); if (CurrentInstance != null) { GreatPushUtils.Log("More than one GreatPush instance has been initialized. Please use the instance method greatPush.getBundleUrlInternal() to get the correct bundleURL for a particular instance."); } CurrentInstance = this; }
public async void downloadUpdate(JObject updatePackage, bool notifyProgress, IPromise promise) { try { updatePackage[GreatPushConstants.BinaryModifiedTimeKey] = "" + await FileUtils.GetBinaryResourcesModifiedTimeAsync(_greatPush.AssetsBundleFileName).ConfigureAwait(false); await _greatPush.UpdateManager.DownloadPackageAsync( updatePackage, _greatPush.AssetsBundleFileName, new Progress <HttpProgress>( (HttpProgress progress) => { if (!notifyProgress) { return; } var downloadProgress = new JObject() { { "totalBytes", progress.TotalBytesToReceive }, { "receivedBytes", progress.BytesReceived } }; _reactContext .GetJavaScriptModule <RCTDeviceEventEmitter>() .emit(GreatPushConstants.DownloadProgressEventName, downloadProgress); } ) ).ConfigureAwait(false); JObject newPackage = await _greatPush.UpdateManager.GetPackageAsync((string)updatePackage[GreatPushConstants.PackageHashKey]).ConfigureAwait(false); promise.Resolve(newPackage); } catch (InvalidDataException e) { GreatPushUtils.Log(e.ToString()); SettingsManager.SaveFailedUpdate(updatePackage); promise.Reject(e); } catch (Exception e) { GreatPushUtils.Log(e.ToString()); promise.Reject(e); } }
internal static JObject GetPendingUpdate() { var pendingUpdateString = (string)Settings.Values[GreatPushConstants.PendingUpdateKey]; if (pendingUpdateString == null) { return(null); } try { return(JObject.Parse(pendingUpdateString)); } catch (Exception) { // Should not happen. GreatPushUtils.Log("Unable to parse pending update metadata " + pendingUpdateString + " stored in SharedPreferences"); return(null); } }