From 8338a7ecb7443838efe99bc7ecee855f1c7dae78 Mon Sep 17 00:00:00 2001 From: Seth Call Date: Tue, 16 Sep 2014 21:13:36 -0500 Subject: [PATCH] * VRFS-2209 - fix progress bar by fixing the update size variable. also show countdown --- web/app/assets/javascripts/clientUpdate.js | 41 ++++++++++++++----- .../stylesheets/client/clientUpdate.css.scss | 6 +++ web/app/views/clients/_client_update.html.erb | 11 +++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/web/app/assets/javascripts/clientUpdate.js b/web/app/assets/javascripts/clientUpdate.js index a23529154..5df2ce32e 100644 --- a/web/app/assets/javascripts/clientUpdate.js +++ b/web/app/assets/javascripts/clientUpdate.js @@ -10,11 +10,11 @@ var logger = context.JK.logger; var ellipsesJiggleTimer = null; var forceShow = false; // manual test helper + // updated once a download is started var updateUri = null; + var updateSize = 0; app.clientUpdating = false; - // updated once a download is started - var updateSize = 0; function cancelUpdate(e) { if ((e.ctrlKey || e.metaKey) && e.keyCode == 78) { @@ -27,8 +27,10 @@ // responsible for updating the contents of the update dialog // as well as registering for any event handlers function updateClientUpdateDialog(templateId, options) { + options = options || {}; + var template = $('#template-' + templateId).html(); - var templateHtml = context.JK.fillTemplate(template, options); + var templateHtml = context._.template(template, options, {variable: 'data'}); $('#client_update .dialog-inner').html(templateHtml); @@ -69,12 +71,13 @@ /***************************************/ function clientUpdateDownloadProgress(bytesReceived, bytesTotal, downloadSpeedMegSec, timeRemaining) { // this fires way too many times to leave in. uncomment if debugging update feature - //logger.debug("bytesReceived: " + bytesReceived, ", bytesTotal: " + bytesTotal, ", downloadSpeed: " + downloadSpeedMegSec, ", timeRemaining: " + timeRemaining ); + //logger.debug("bytesReceived: " + bytesReceived, ", bytesTotal: " + bytesTotal, ", downloadSpeed: " + downloadSpeedMegSec, ", timeRemaining: " + timeRemaining + ", updateSize: " + updateSize); bytesReceived = Number(bytesReceived) bytesTotal = Number(bytesTotal) // bytesTotal from Qt is not trust worthy; trust server's answer instead - $('#progress-bar').width(((bytesReceived / updateSize) * 100).toString() + "%") + var progressWidth = ((bytesReceived / updateSize) * 100).toString() + "%"; + $('#progress-bar').width(progressWidth) //$("#progressbar_detail").text(parseInt(bytesReceived) + "/" + parseInt(updateSize)) } @@ -98,10 +101,27 @@ } - function clientUpdateLaunchSuccess(updateLocation) { - logger.debug("client update launched successfully to: " + updateLocation); + function clientUpdateLaunchSuccess(userTimeToRead) { + if(userTimeToRead === undefined) { + userTimeToRead = 1000; // older clients didn't pass this in, and exit very quickly + } - updateClientUpdateDialog("update-restarting"); + logger.debug("client update launching in: " + userTimeToRead); + + // set timer to update countdown + var rounded = Math.round(userTimeToRead / 1000); + + // simple countdown timer + var timer = setInterval(function(){ + var $countdown = $('#client_update .countdown-secs'); + var countdown = parseInt($countdown.text()); + $countdown.text(countdown - 1); + if(countdown == 0) { + clearInterval(timer); + } + }, rounded * 1000); + + updateClientUpdateDialog("update-restarting", {countdown: rounded, os: context.JK.GetOSAsString()}); } function clientUpdateLaunchFailure(errorMsg) { @@ -167,7 +187,7 @@ } } - function runCheck(product, version, uri, updateSize, currentVersion) { + function runCheck(product, version, uri, size, currentVersion) { if(currentVersion === undefined) { currentVersion = context.jamClient.ClientUpdateVersion(); @@ -191,6 +211,7 @@ if (shouldUpdate(currentVersion, version)) { app.clientUpdating = true; updateUri = uri; + updateSize = size; if(context.JK.CurrentSessionModel && context.JK.CurrentSessionModel.inSession()) { logger.debug("deferring client update because in session") @@ -210,7 +231,7 @@ // check if updated is needed function check() { - var os = context.jamClient.GetOSAsString(); + var os = context.JK.GetOSAsString(); // check kill switch before all other logic if (!gon.check_for_client_updates) { diff --git a/web/app/assets/stylesheets/client/clientUpdate.css.scss b/web/app/assets/stylesheets/client/clientUpdate.css.scss index b22d78295..cc0321127 100644 --- a/web/app/assets/stylesheets/client/clientUpdate.css.scss +++ b/web/app/assets/stylesheets/client/clientUpdate.css.scss @@ -22,6 +22,12 @@ display:block; } + .countdown-secs { + font-size:24px; + display:inline-block; + width:15px; + } + h2 { font-weight:bold; font-size:x-large; diff --git a/web/app/views/clients/_client_update.html.erb b/web/app/views/clients/_client_update.html.erb index 51987a3a2..17fe2b868 100644 --- a/web/app/views/clients/_client_update.html.erb +++ b/web/app/views/clients/_client_update.html.erb @@ -75,8 +75,13 @@

- This application will close automatically in a moment. - If it does not close, please restart it manually. + {% if(data.os == 'MacOSX') { %} + This application will close automatically in {{data.countdown}} {{data.countdown == 1 ? 'second' : 'seconds'}}. + If it does not close, please restart it manually or download the latest JamKazam from our downloads page. + {% } else { %} + The updater will launch automatically in {{data.countdown}} seconds. + If you do not see a Windows updater, please restart it manually or download the latest JamKazam from our downloads page. + {% } %}
@@ -90,7 +95,7 @@

Download the latest JamKazam from our downloads page.

- {error_msg} + {{data.error_msg}}