Make gkeep understand list indentation, tweaks to the countdown bar in
[kiosk.git] / kiosk.py
index 5bc28cda4843aba9428c20bf162109173b8ac1eb..fd509101804bf41312d77eccc01ea99b91500bc6 100755 (executable)
--- a/kiosk.py
+++ b/kiosk.py
@@ -172,29 +172,28 @@ def emit_wrapped(f, filename):
     return new Promise(resolve => setTimeout(resolve, milliseconds))
   }
 
-  var loaded = false;
   var loadedDate = new Date();
 
   addLoadEvent(zoomScreen);
   addLoadEvent(runClock);
   addLoadEvent(lateLoadImages);
-  addLoadEvent(function() {
-    loaded = true;
-  });
 
-  // Reload the page after a certain amount of time has passed or
-  // immediately if told to do so.
-  (function poll() {
+  // Runs the countdown line at the bottom and is responsible for
+  // normal page reloads caused by the expiration of a timer.
+  (function countdown() {
     setTimeout(
       function() {
         var now = new Date();
         var deltaMs = now.getTime() - loadedDate.getTime();
-
         var totalMs = %d;
         var remainingMs = (totalMs - deltaMs);
+
         if (remainingMs > 0) {
           var hr = document.getElementById("countdown");
-          var width = (remainingMs / totalMs) * 100.0;
+          var width = (remainingMs / (totalMs - 5000)) * 100.0;
+          if (width > 100) {
+            width = 100;
+          }
           hr.style.width = " ".concat(width, "%%");
           hr.style.backgroundColor = "maroon";
         } else {
@@ -202,7 +201,17 @@ def emit_wrapped(f, filename):
           window.location.reload();
         }
 
-        // Also reload immediately if told to do so.
+        // Brief sleep before doing it all over again.
+        sleep(50).then(() => {
+          countdown();
+        });
+      }, 50)
+  })();
+
+  // Periodically checks for emergency reload events.
+  (function poll() {
+    setTimeout(
+      function() {
         var xhr = new XMLHttpRequest();
         xhr.open('GET',
                  'http://wannabe.house/kiosk/pages/reload_immediately.html');