[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-launcher/master] Bug 23240: retrieve current bootstrap progress before showing progress bar



commit 26d284e3835ddd5b283b732278b7b5b740bace6e
Author: Kathy Brade <brade@xxxxxxxxxxxxxxxxx>
Date:   Mon Aug 14 16:09:47 2017 -0400

    Bug 23240: retrieve current bootstrap progress before showing progress bar
    
    To avoid showing an incorrect progress value, keep the progress bar
    hidden until after we have retrieved the current bootstrap progress value.
---
 src/chrome/content/progress.js  | 28 +++++++++++++++++++++++++++-
 src/chrome/content/progress.xul |  5 +++--
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/src/chrome/content/progress.js b/src/chrome/content/progress.js
index 48362e7..f7bcaff 100644
--- a/src/chrome/content/progress.js
+++ b/src/chrome/content/progress.js
@@ -1,4 +1,4 @@
-// Copyright (c) 2015, The Tor Project, Inc.
+// Copyright (c) 2017, The Tor Project, Inc.
 // See LICENSE for licensing information.
 //
 // vim: set sw=2 sts=2 ts=8 et syntax=javascript:
@@ -81,6 +81,16 @@ function initDialog()
     if (pleaseWait)
       pleaseWait.removeAttribute("hidden");
   }
+
+  // To avoid showing an incorrect progress value, we keep the progress bar
+  // hidden until a TorBootstrapStatus notification is received. We request
+  // the most recent bootstrap status info (which should cause such a
+  // notification to be generated) and also start a fail-safe timer to ensure
+  // that the progress bar is displayed within 2 seconds in all cases.
+  let protocolSvc = Cc["@torproject.org/torlauncher-protocol-service;1"]
+                      .getService(Ci.nsISupports).wrappedJSObject;
+  protocolSvc.TorRetrieveBootstrapStatus();
+  window.setTimeout(function() { showProgressMeterIfNoError(); }, 2000);
 }
 
 
@@ -158,6 +168,17 @@ function stopTorBootstrap()
 }
 
 
+function showProgressMeterIfNoError()
+{
+  let meter = document.getElementById("progressMeter");
+  if (meter &&
+      !document.documentElement.hasAttribute("bootstrapErrorOccurred"))
+  {
+    meter.style.visibility = "visible";
+  }
+}
+
+
 var gObserver = {
   // nsIObserver implementation.
   observe: function(aSubject, aTopic, aParam)
@@ -184,7 +205,10 @@ var gObserver = {
 
       var meter = document.getElementById("progressMeter");
       if (meter)
+      {
         meter.value = percentComplete;
+        showProgressMeterIfNoError();
+      }
 
       var bootstrapDidComplete = (percentComplete >= 100);
       if (percentComplete >= 100)
@@ -199,6 +223,8 @@ var gObserver = {
         if (s)
           labelText = s;
 
+        document.documentElement.setAttribute("bootstrapErrorOccurred", true);
+
         if (meter)
           meter.setAttribute("hidden", true);
 
diff --git a/src/chrome/content/progress.xul b/src/chrome/content/progress.xul
index 473dab9..5b26110 100644
--- a/src/chrome/content/progress.xul
+++ b/src/chrome/content/progress.xul
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <!--
-   - Copyright (c) 2014, The Tor Project, Inc.
+   - Copyright (c) 2017, The Tor Project, Inc.
    - See LICENSE for licensing information.
    - vim: set sw=2 sts=2 ts=8 et syntax=xml:
   -->
@@ -37,7 +37,8 @@
         <description id="progressDesc" />
       </vbox>
     </hbox>
-    <progressmeter id="progressMeter" mode="determined" value="0" />
+    <progressmeter id="progressMeter" mode="determined" value="0"
+                   style="visibility:hidden" />
     <description id="progressPleaseWait"
                  hidden="true">&torprogress.pleaseWait;</description>
   </vbox>

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits