More fuckery with indented sublists in gkeep and with the countdown line.
[kiosk.git] / kiosk.py
index f25a659c17bb153a08281b0c5c5743ad59fde0d4..6003165a674e1f2ed76f18f8ffe8812f7c67b6e5 100755 (executable)
--- a/kiosk.py
+++ b/kiosk.py
@@ -172,30 +172,46 @@ 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);
 
-        // Reload unconditionally after 22 sec.
-        if (deltaMs > %d) {
+        if (remainingMs > 0) {
+          var hr = document.getElementById("countdown");
+          var width = (remainingMs / (totalMs - 5000)) * 100.0;
+          if (width <= 100) {
+            hr.style.visibility = "visible";
+            hr.style.width = " ".concat(width, "%%");
+            hr.style.backgroundColor = "maroon";
+          }
+        } else {
+          // Reload unconditionally after 22 sec.
           window.location.reload();
         }
 
-        // Reload immediately if told.
+        // 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');
@@ -238,6 +254,14 @@ def emit_wrapped(f, filename):
             <P ALIGN="right">
                 <FONT SIZE=2 COLOR=#bbbbbb>%s @ %s ago.</FONT>
             </P>
+            <HR id="countdown" STYLE="width:0px;
+                                      text-align:left;
+                                      margin:0;
+                                      border:none;
+                                      border-width:0;
+                                      height:5px;
+                                      visibility:hidden;
+                                      background-color:#ffffff;">
         </TD>
     </TR>
     </TABLE>
@@ -254,7 +278,6 @@ def thread_invoke_renderers():
             utils.timestamp()))
         for r in renderer_catalog.get_renderers():
             now = time.time()
-            print("renderer[%s]: Rendering %s" % (utils.timestamp(), r.get_name()))
             try:
                 r.render()
             except Exception as e:
@@ -266,8 +289,9 @@ def thread_invoke_renderers():
                 print("renderer[%s] unknown error in %s, swallowing it." % (
                     utils.timestamp(), r.get_name()))
             delta = time.time() - now
-            print("renderer[%s]: Back from %s, that took %5.2fs." % (
-                utils.timestamp(), r.get_name(), delta))
+            if (delta > 1.0):
+                print("renderer[%s]: Warning: %s's rendering took %5.2fs." % (
+                    utils.timestamp(), r.get_name(), delta))
         print("renderer[%s]: thread having a little break for %ds..." % (
             utils.timestamp(), constants.render_period_sec))
         time.sleep(constants.render_period_sec)