Open anssiko opened 2 years ago
For info, I've played a bit with this high-level API and created a quick demo at https://high-level-battery-api.glitch.me/
You can look at the source code at https://glitch.com/edit/#!/high-level-battery-api?path=index.js
It looks like this:
const battery = await navigator.getBattery();
battery.addEventListener("levelchange", () => {
if (battery.level < 0.1) {
battery.dispatchEvent(new Event("lowpower"));
} else if (battery.level === 1) {
battery.dispatchEvent(new Event("fullpower"));
}
});
@beaufortfrancois thanks! This is on our TPAC agenda https://github.com/w3c/devicesensors-wg/issues/56
Here’s a rather hilarious use case that would be enabled by such a high-level API: Die With Me, “[t]he chat app you can only use when you have less than 5% battery”.
via https://bugs.chromium.org/p/chromium/issues/detail?id=661792#c49
See also https://github.com/w3c/battery/issues/25#issuecomment-1027316300