improve status messages
authorRobert Kaiser <robert@widebook.box.kairo.at>
Mon, 2 Sep 2013 16:02:17 +0000 (18:02 +0200)
committerRobert Kaiser <robert@widebook.box.kairo.at>
Mon, 2 Sep 2013 16:02:17 +0000 (18:02 +0200)
js/tricorder.js

index f88ebb120e470277fc7818a1d35a095e2ff76a5e..ff53ccb176bc28d9f5f58a907ee5a7edd360cb55 100644 (file)
@@ -226,10 +226,28 @@ var gModDev = {
     gSounds.scan.pause();
   },
   updateBattery: function() {
-    document.getElementById("devBattLevel").textContent = (navigator.battery.level * 100).toFixed(1) + "%";
-    document.getElementById("devBattStatus").textContent = 
-        navigator.battery.charging ? "charging, " + navigator.battery.chargingTime + "s remaining"
-                                   : navigator.battery.dischargingTime + "s usage remaining";
+    document.getElementById("devBattLevel").textContent =
+        (navigator.battery.level * 100).toFixed(1) + "%";
+    if (navigator.battery.charging) {
+      if (navigator.battery.chargingTime == 0 ||
+          navigator.battery.chargingTime == Infinity) {
+        document.getElementById("devBattStatus").textContent = "charging";
+      }
+      else {
+        document.getElementById("devBattStatus").textContent = 
+            "charging, " + navigator.battery.chargingTime + "s remaining";
+      }
+    }
+    else {
+      if (navigator.battery.dischargingTime == 0 ||
+          navigator.battery.dischargingTime == Infinity) {
+        document.getElementById("devBattStatus").textContent = "discharging";
+      }
+      else {
+        document.getElementById("devBattStatus").textContent = 
+            navigator.battery.dischargingTime + "s usage remaining";
+      }
+    }
   },
   batteryTimer: null,
 }