[SOLVED ] How to update Appcenter downloading dialog

:wave:t3: Is it mandatory to call setInterval in order to update dialog's Text and Progress

:point_right: Inside codePush.sync() code is as follows,

function downloadProgress(downloadProgress) {
      var progress = 0;
      var dialog = app.dialog.progress("Downloading", progress);
      dialog.setText("Setting you up 0%");
      if (downloadProgress) {
          console.log("progress", downloadProgress);
          var received = downloadProgress.receivedBytes;
          var total = downloadProgress.totalBytes;

          progress = Math.trunc((received * 100) / total);
          dialog.setProgress((received * 100) / total);
          dialog.setText(
            "Setting you up " + Math.trunc((received * 100) / total) + "%"
          );
        }
      } else {
              app.dialog.close();
      }      
    }

:point_right: In console.log("progress", downloadProgress) shows async data as it downloads bytes

:point_right: dialog opens with text and progress but do not updates

:point_right: when I declare dialog var outside codePush.sync , dialog gets initialized. and it works

but,

:point_right: user see dialog open without any action or callback

:timer_clock: my second try:

async function createDialog(received,total){
this.received = received;
this.total = total;
var dialog = await app.dialog.progress("Downloading", 0);
return dialog;
} 
...
//inside codePush.sync() callback
function downloadProgress(downloadProgress){
if(downloadProgress){
var received = downloadProgress.receivedBytes;
var total = downloadProgress.totalBytes;
    createDialog.call(this,received,total).then((dialog)=>{
// getting dialog here !!!!
    dialog.setProgress((received * 100) / total); // do not set progress
    dialog.setText("Setting you up " + Math.trunc((received * 100) / total) + "%"); // do not set text
   })
}
else {
   app.dialog.close();}
}

:point_right: It will be helpful, if anyone tell me how can we return received and total with dialog obj that we can receive those two params in .then callback

:point_right: appreciate reply / code snippet / article / resources

Thank you

:cucumber: Resolved

async function createDialog() {
    const dialog = await app.dialog.progress("Downloading", 0);
    return dialog;
  }
createDialog().then((dialog)=>{
    // dialog instance
    codePush.sync(null,options,function(downloadProgress){
        if(downloadProgress){
            //setTitle, setProgress, setText 
        } else {
            app.dialog.close();
        }
    })
}).catch(err =>{ app.dialog.close();})

Mind reply if anyone have better way ! :bug: :stop_sign:

1 Like