04-22-2021 06:15 - edited 04-30-2021 07:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-22-2021 06:15 - edited 04-30-2021 07:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
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.
Accepted Solutions
04-30-2021 07:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 07:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 06:34
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Move this inside your clock tick event.
batteryHandle.text = `${battery.chargeLevel}`;

04-30-2021 07:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-30-2021 07:06
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
I am slightly confused by what you mean. Would you mind being a bit more specific?

04-30-2021 07:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


04-30-2021 07:46
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
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
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

04-30-2021 08:07 - edited 04-30-2021 08:18
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
Thank you so much. Your solution worked!
