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:

  http://dev.w3.org/2009/dap/system-info/battery-status.html#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!

-Anssi
Received on Tuesday, 19 April 2011 15:12:33 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 9 May 2012 00:14:20 GMT