Browse Source

Handle unknown battery status

Danilo Bargen 7 years ago
parent
commit
7212e53b92
2 changed files with 7 additions and 1 deletions
  1. 6 0
      src/services/battery.ts
  2. 1 1
      src/threema.d.ts

+ 6 - 0
src/services/battery.ts

@@ -42,6 +42,12 @@ export class BatteryStatusService {
      * Update the battery status.
      */
     public setStatus(batteryStatus: threema.BatteryStatus): void {
+        // Handle null percent value. This can happen if the battery status could not be determined.
+        if (batteryStatus.percent === null) {
+            this.batteryStatus = null;
+            return;
+        }
+
         this.batteryStatus = batteryStatus;
 
         // Alert if percent drops below a certain threshold

+ 1 - 1
src/threema.d.ts

@@ -655,7 +655,7 @@ declare namespace threema {
     }
 
     interface BatteryStatus {
-        percent: number;
+        percent: number | null;
         isCharging: boolean;
     }