04-22-2021 06:15 - edited 04-30-2021 07:06
04-22-2021 06:15 - edited 04-30-2021 07:06
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?
Answered! Go to the Best Answer.
04-30-2021 07:46
04-30-2021 07:46
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} `;
});
04-30-2021 06:34
04-30-2021 06:34
Move this inside your clock tick event.
batteryHandle.text = `${battery.chargeLevel}`;
04-30-2021 07:06
04-30-2021 07:06
I am slightly confused by what you mean. Would you mind being a bit more specific?
04-30-2021 07:46
04-30-2021 07:46
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} `;
});
04-30-2021 08:07 - edited 04-30-2021 08:18
04-30-2021 08:07 - edited 04-30-2021 08:18
Thank you so much. Your solution worked!