W3C home > Mailing lists > Public > public-device-apis@w3.org > April 2011

Re: CfC: Battery Status Event FPWD

From: Anssi Kostiainen <anssi.kostiainen@nokia.com>
Date: Tue, 19 Apr 2011 18:12:27 +0300
CC: Robin Berjon <robin@berjon.com>, <public-device-apis@w3.org>
Message-ID: <595341DA-AA70-4942-9ACE-F824617139D6@nokia.com>
To: ext Antoine Sanchez <ckkoshi@gmail.com>
Hi Antoine,

On 19.4.2011, at 14.54, ext Antoine Sanchez wrote:

> Hello, the event is a good idea, but how can we get the battery status
> on load ?
> initBatteryStatusEvent() doesn't return anything? it should be nice to
> have an object battery:
> {
>    isBattery:bool,
>    isCharging:bool,
>    level:int,
>    timeRemaining:null
> };

I believe your use case is related to real events, not synthetic ones? In that case, to get the battery status as soon as possible after the 'load' event has been fired you should do it as described in the Examples:


Currently the spec says: "The User Agent must dispatch a BatteryStatusEvent event immediately". That's ambiguous and an item to be fleshed out. I've envisioned that "immediate" would mean "queue as a post-load task" but the details are still to be defined. The HTML5 spec goes into detail about the process (http://dev.w3.org/html5/spec/the-end.html), but most importantly, the event would get dispatched only after e.g. the 'DOMContentLoaded' and 'load' events have been fired. So technically, it would never really fire "on load".

You would only want to call the initBatteryStatusEvent() if you wish to create a synthesized event. If that's the case, you'll first have to create the event via document.createEvent(), then prepare the event by invoking event.initBatteryStatusEvent(), and finally dispatch it via window.dispatchEvent() (or o.dispatchEvent() if you're synthesizing a battery status event for an auxiliary device exposed on the o object).

> also, it would be easier that level is a %, to avoid problem like each
> navigator use is own level (5, 10, 100).

Actually, the level is meant to be a %. It seems we'll have to make that clearer. Thanks for the remark!

Received on Tuesday, 19 April 2011 15:12:33 UTC

This archive was generated by hypermail 2.3.1 : Monday, 23 October 2017 14:53:48 UTC