microsoft / cordova-plugin-code-push

Cordova plugin for CodePush
http://appcenter.ms
Other
644 stars 335 forks source link

How to call onProgress function #652

Open PRA1995SAG opened 4 years ago

PRA1995SAG commented 4 years ago

Description

I'm using window.codePush.checkForUpdate(onUpdateCheck, onError); from docs

remote package gets downloaded & installed

onProgress callback do not executes on remotePackage.download(onPackageDownloaded, onError, onProgress);

Reproduction

function checkForUpdates(app){
     codePush.checkForUpdate(function (remotePackage) {
     if (!remotePackage) {
       app.dialog.close();
     } else {
       navigator.notification.confirm(
         "Please us to serve you more !",
         // continue callback
         function () {
           console.log("inside continue callback");
           var progressDialog = app.dialog.progress(
             "TITLE",
             "Setting you up ",
             0
           );
           remotePackage.download(
             //onPackageDownloaded
             function (localPackage) {
               app.dialog.close();
               localPackage.install(
                 //onInstallSuccess
                 function () {
                   navigator.notification.alert(
                     "You are up to date with us!", // message
                     function () {}, // callback
                     "TITLE", // title
                     "close" // buttonName
                   );
                 },
                 //onError
                 function (err) {
                   console.log("err", err);
                 },
                 {
                   installMode: InstallMode.IMMEDIATE,
                   minimumBackgroundDuration: 120,
                   mandatoryInstallMode: InstallMode.IMMEDIATE,
                 }
               );
             },
             //onError
             function (error) {
               console.log("err: ", error);
             },
             //onProgress DO NOT EXECUTES
             function (downloadProgress) {
              // DO NOT EXECUTES
               console.log("inside download progress");
               console.log(downloadProgress);
               progressDialog.setProgress(
                 Math.trunc(
                   (downloadProgress.receivedBytes * 100) /
                     downloadProgress.totalBytes
                 )
               );
               progressDialog.setText(
                 "Setting you up " +
                   Math.trunc(
                     (downloadProgress.receivedBytes * 100) /
                       downloadProgress.totalBytes
                   ) +
                   "%"
               );
             }
           );
         },
         "Update available",
        ["Continue"]
       );
    }
   }, null);
}
export { checkForUpdates };

Additional Information

more on topic

At this time of posting, I'm sure, this is not a bug. I checked codepush in my other projects (platform - cordova). onprogress callback works fine

  • I've created seperate codepush.js file and linked it below index.html works

Above code @Reproduction is taken from project where I use Webpack

  • so, i've made seperate codepush.js file. and exporting that.
  • also i've put codePush.notifyApplicationReady(); call at deviceReady
  • new update downloads, installs, but downloadProgress do not execute even do not logs

appreciate any guidance/article/resources

Thank You.
pitAlex commented 4 years ago

If you are using the latest because they use cordova-plugin-advanced-http plugin, the progress call will not be triggered as that plugin does not have a progress report. I switched it to use cordova-plugin-sslsupport

nguyendinhdoan commented 4 years ago

I'm getting the same problem with v1.13.1

PRA1995SAG commented 4 years ago
PRA1995SAG commented 4 years ago

If you are using the latest because they use cordova-plugin-advanced-http plugin, the progress call will not be triggered as that plugin does not have a progress report. I switched it to use cordova-plugin-sslsupport

can you show some relevant example/ refer any guide

Coder7777 commented 3 years ago

I'm getting the same problem with v1.13.1

You can try v1.12.0, I downgrade to this version, the downloadProgress callback function working well.

Good luck for you.

https://www.npmjs.com/package/cordova-plugin-code-push/v/1.12.0

pitAlex commented 3 years ago

If you are using the latest because they use cordova-plugin-advanced-http plugin, the progress call will not be triggered as that plugin does not have a progress report. I switched it to use cordova-plugin-sslsupport

can you show some relevant example/ refer any guide

Hi, sorry for my...quite late response, but to use the other plugin 2 changes are needed. One in httpRequester.js and the other in remotePackage.js. I am giving you 2 screenshots that show the changes via a diff tool to help with making it easier to understand.

Screen Shot 2021-04-26 at 10 50 07 PM Screen Shot 2021-04-26 at 10 49 32 PM
PRA1995SAG commented 3 years ago

If you are using the latest because they use cordova-plugin-advanced-http plugin, the progress call will not be triggered as that plugin does not have a progress report. I switched it to use cordova-plugin-sslsupport

can you show some relevant example/ refer any guide

Hi, sorry for my...quite late response, but to use the other plugin 2 changes are needed. One in httpRequester.js and the other in remotePackage.js. I am giving you 2 screenshots that show the changes via a diff tool to help with making it easier to understand.

Screen Shot 2021-04-26 at 10 50 07 PM Screen Shot 2021-04-26 at 10 49 32 PM

šŸ‘šŸ¼