internal void InitializeUpdateAfterRestart() { JObject pendingUpdate = SettingsManager.GetPendingUpdate(); if (pendingUpdate != null) { var updateIsLoading = (bool)pendingUpdate[CodePushConstants.PendingUpdateIsLoadingKey]; if (updateIsLoading) { // Pending update was initialized, but notifyApplicationReady was not called. // Therefore, deduce that it is a broken update and rollback. CodePushUtils.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 (MainPage.UseDeveloperSupport) { 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[CodePushConstants.PendingUpdateHashKey], /* isLoading */ true); } } }
public void downloadUpdate(JObject updatePackage, bool notifyProgress, IPromise promise) { Action downloadAction = async() => { try { updatePackage[CodePushConstants.BinaryModifiedTimeKey] = "" + await _codePush.GetBinaryResourcesModifiedTime(); await _codePush.UpdateManager.DownloadPackage( updatePackage, _codePush.AssetsBundleFileName, new Progress <HttpProgress>( (HttpProgress progress) => { if (!notifyProgress) { return; } var downloadProgress = new JObject() { { "totalBytes", progress.TotalBytesToReceive }, { "receivedBytes", progress.BytesReceived } }; _reactContext .GetJavaScriptModule <RCTDeviceEventEmitter>() .emit(CodePushConstants.DownloadProgressEventName, downloadProgress); } ) ); JObject newPackage = await _codePush.UpdateManager.GetPackage((string)updatePackage[CodePushConstants.PackageHashKey]); promise.Resolve(newPackage); } catch (InvalidDataException e) { CodePushUtils.Log(e.ToString()); SettingsManager.SaveFailedUpdate(updatePackage); promise.Reject(e); } catch (Exception e) { CodePushUtils.Log(e.ToString()); promise.Reject(e); } }; Context.RunOnNativeModulesQueueThread(downloadAction); }
public CodePushReactPackage(string deploymentKey, ReactPage mainPage) { AppVersion = CodePushUtils.GetAppVersion(); DeploymentKey = deploymentKey; MainPage = mainPage; UpdateManager = new UpdateManager(); if (CurrentInstance != null) { CodePushUtils.Log("More than one CodePush instance has been initialized. Please use the instance method codePush.getBundleUrlInternal() to get the correct bundleURL for a particular instance."); } CurrentInstance = this; }
public CodePushReactPackage(string deploymentKey, ReactPage mainPage) { AppVersion = Package.Current.Id.Version.Major + "." + Package.Current.Id.Version.Minor + "." + Package.Current.Id.Version.Build; DeploymentKey = deploymentKey; MainPage = mainPage; UpdateManager = new UpdateManager(); IsRunningBinaryVersion = false; // TODO implement telemetryManager // _codePushTelemetryManager = new CodePushTelemetryManager(this.applicationContext, CODE_PUSH_PREFERENCES); if (CurrentInstance != null) { CodePushUtils.Log("More than one CodePush instance has been initialized. Please use the instance method codePush.getBundleUrlInternal() to get the correct bundleURL for a particular instance."); } CurrentInstance = this; }
internal static JObject GetPendingUpdate() { var pendingUpdateString = (string)Settings.Values[CodePushConstants.PendingUpdateKey]; if (pendingUpdateString == null) { return(null); } try { return(JObject.Parse(pendingUpdateString)); } catch (Exception) { // Should not happen. CodePushUtils.Log("Unable to parse pending update metadata " + pendingUpdateString + " stored in SharedPreferences"); return(null); } }