Exemplo n.º 1
0
        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);
                }
            }
        }
Exemplo n.º 2
0
        internal static Task <long> GetBinaryResourcesModifiedTimeAsync(string fileName)
        {
            var pathToAssembly         = GreatPushUtils.GetAppFolder();
            var pathToAssemblyResource = Path.Combine(pathToAssembly, GreatPushConstants.AssetsBundlePrefix, fileName);
            var lastUpdateTime         = File.GetCreationTime(pathToAssemblyResource);

            return(Task.FromResult(new DateTimeOffset(lastUpdateTime).ToUnixTimeMilliseconds()));
        }
Exemplo n.º 3
0
        public async Task <string> GetJavaScriptBundleFileAsync(string assetsBundleFileName)
        {
            AssetsBundleFileName = assetsBundleFileName;
            string binaryJsBundleUrl = GreatPushUtils.GetAssetsBundlePrefix() + assetsBundleFileName;

            var binaryResourcesModifiedTime = await FileUtils.GetBinaryResourcesModifiedTimeAsync(AssetsBundleFileName).ConfigureAwait(false);

            var packageFile = await UpdateManager.GetCurrentPackageBundleAsync(AssetsBundleFileName).ConfigureAwait(false);

            if (packageFile == null)
            {
                // There has not been any downloaded updates.
                GreatPushUtils.LogBundleUrl(binaryJsBundleUrl);
                IsRunningBinaryVersion = true;
                return(binaryJsBundleUrl);
            }

            var packageMetadata = await UpdateManager.GetCurrentPackageAsync().ConfigureAwait(false);

            long?binaryModifiedDateDuringPackageInstall       = null;
            var  binaryModifiedDateDuringPackageInstallString = (string)packageMetadata[GreatPushConstants.BinaryModifiedTimeKey];

            if (binaryModifiedDateDuringPackageInstallString != null)
            {
                binaryModifiedDateDuringPackageInstall = long.Parse(binaryModifiedDateDuringPackageInstallString);
            }

            var packageAppVersion = (string)packageMetadata["appVersion"];

            if (binaryModifiedDateDuringPackageInstall != null &&
                binaryModifiedDateDuringPackageInstall == binaryResourcesModifiedTime &&
                AppVersion.Equals(packageAppVersion))
            {
                GreatPushUtils.LogBundleUrl(packageFile.Path);
                IsRunningBinaryVersion = false;

                return(GreatPushUtils.GetFileBundlePrefix() + GreatPushUtils.ExtractSubFolder(packageFile.Path));
            }
            else
            {
                // The binary version is newer.
                DidUpdate = false;
                if (!UseDeveloperSupport || !AppVersion.Equals(packageAppVersion))
                {
                    await ClearUpdatesAsync().ConfigureAwait(false);
                }

                GreatPushUtils.LogBundleUrl(binaryJsBundleUrl);
                IsRunningBinaryVersion = true;
                return(binaryJsBundleUrl);
            }
        }
Exemplo n.º 4
0
        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;
        }
        internal async static Task CopyNecessaryFilesFromCurrentPackageAsync(StorageFile diffManifestFile, StorageFolder currentPackageFolder, StorageFolder newPackageFolder)
        {
            await FileUtils.MergeFoldersAsync(currentPackageFolder, newPackageFolder).ConfigureAwait(false);

            JObject diffManifest = await GreatPushUtils.GetJObjectFromFileAsync(diffManifestFile).ConfigureAwait(false);

            var deletedFiles = (JArray)diffManifest["deletedFiles"];

            foreach (string fileNameToDelete in deletedFiles)
            {
                StorageFile fileToDelete = await newPackageFolder.GetFileAsync(fileNameToDelete.Replace("/", "\\")).AsTask().ConfigureAwait(false);

                await fileToDelete.DeleteAsync().AsTask().ConfigureAwait(false);
            }
        }
Exemplo n.º 6
0
#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);
            }
        }
Exemplo n.º 8
0
        private async Task <JObject> GetCurrentPackageInfoAsync()
        {
            var statusFile = await GetStatusFileAsync().ConfigureAwait(false);

            var info = await GreatPushUtils.GetJObjectFromFileAsync(statusFile).ConfigureAwait(false);

            if (info != null)
            {
                return(info);
            }

            // info file has been corrupted - re-create it
            await statusFile.DeleteAsync().ConfigureAwait(false);

            statusFile = await GetStatusFileAsync().ConfigureAwait(false);

            return(await GreatPushUtils.GetJObjectFromFileAsync(statusFile).ConfigureAwait(false));
        }
        public void getConfiguration(IPromise promise)
        {
            var config = new JObject
            {
                { "appVersion", _greatPush.AppVersion },
                { "clientUniqueId", GreatPushUtils.GetDeviceId() },
                { "deploymentKey", _greatPush.DeploymentKey },
                { "serverUrl", GreatPushConstants.GreatPushServerUrl }
            };

            // TODO generate binary hash
            // string binaryHash = GreatPushUpdateUtils.getHashForBinaryContents(mainActivity, isDebugMode);

            /*if (binaryHash != null)
             * {
             *  configMap.putString(PACKAGE_HASH_KEY, binaryHash);
             * }*/
            promise.Resolve(config);
        }
        internal async Task <JObject> GetPackageAsync(string packageHash)
        {
            StorageFolder packageFolder = await GetPackageFolderAsync(packageHash, false).ConfigureAwait(false);

            if (packageFolder == null)
            {
                return(null);
            }

            try
            {
                StorageFile packageFile = await packageFolder.GetFileAsync(GreatPushConstants.PackageFileName).AsTask().ConfigureAwait(false);

                return(await GreatPushUtils.GetJObjectFromFileAsync(packageFile).ConfigureAwait(false));
            }
            catch (IOException)
            {
                return(null);
            }
        }
Exemplo n.º 11
0
        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);
            }
        }
        private async Task <JObject> GetCurrentPackageInfoAsync()
        {
            StorageFile statusFile = await GetStatusFileAsync().ConfigureAwait(false);

            return(await GreatPushUtils.GetJObjectFromFileAsync(statusFile).ConfigureAwait(false));
        }
Exemplo n.º 13
0
        internal static async Task <IFolder> GetGreatPushFolderAsync()
        {
            var pathToGreatPush = Path.Combine(GreatPushUtils.GetFileBundlePrefix(), GreatPushConstants.GreatPushFolderPrefix);

            return(await FileSystem.Current.LocalStorage.CreateFolderAsync(pathToGreatPush, CreationCollisionOption.OpenIfExists).ConfigureAwait(false));
        }