Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Update Battery Level on Screen Wake

ANSWERED

I want to have to battery level update in my clockface constantly, like every minute or so. It currently refreshes only when I go back to the clock face from another app, and there is a noticeable delay.

 

This is the code I have:

const batteryHandle = document.getElementById("batteryLabel");
batteryHandle.text = `${battery.chargeLevel} `;

 

Any suggestions?

Best Answer
1 BEST ANSWER

Accepted Solutions

Yeah, something like

 

import clock from "clock";
import { battery } from "power";

const batteryHandle = document.getElementById("batteryLabel");

clock.granularity = "minutes"; // seconds, minutes, or hours

clock.addEventListener("tick", (evt) => {
  // tick every minute
  batteryHandle.text = `${battery.chargeLevel} `;
});

View best answer in original post

Best Answer
0 Votes
4 REPLIES 4

Move this inside your clock tick event.

 

batteryHandle.text = `${battery.chargeLevel}`;

 

Best Answer
0 Votes

I am slightly confused by what you mean. Would you mind being a bit more specific?

Best Answer
0 Votes

Yeah, something like

 

import clock from "clock";
import { battery } from "power";

const batteryHandle = document.getElementById("batteryLabel");

clock.granularity = "minutes"; // seconds, minutes, or hours

clock.addEventListener("tick", (evt) => {
  // tick every minute
  batteryHandle.text = `${battery.chargeLevel} `;
});
Best Answer
0 Votes

Thank you so much. Your solution worked! 

Best Answer