W3C home > Mailing lists > Public > public-device-apis@w3.org > March 2012

Re: Comments about battery status API

From: Anssi Kostiainen <anssi.kostiainen@nokia.com>
Date: Mon, 19 Mar 2012 13:07:36 +0200
Cc: (wrong string) 联通集团技术部) <chenbo69@chinaunicom.cn>
Message-Id: <E5A57260-6264-4839-9E19-67C44F2BCB90@nokia.com>
To: ext jianglin9 <jianglin9@chinaunicom.cn>
Hi Derek,

On 16.3.2012, at 11.11, ext jianglin9 wrote:

> 1) Suggest changing the chargingTime, dischargingTime, onchargingtimechange and ondischargingtimechange attributes as optional.

The spec defines default values for the attributes. That allows the same code path to be used for supported and not supported cases in a future proof way. This minimizes the fingerprinting surface too.

Let's take an example. If there's no support for the dischargingTime attribute, the following condition will evaluate to false (because the attribute is set to the value positive Infinity):

if (navigator.battery.dischargingTime < 60 * 10) {
  // ...

The same code will continue to work as intended if the support is added later on.

> 2) Alternatively, by frequently retrieving the level attribute, a web app could get aware of the current battery power status, and be able to adjust its behavior.
> In addition to the charging attribute, is it possible to add a readonly DOMString type attribute state with a corresponding Function onstatechange(or other suitable names) to reflect some more informative battery status? For example, over charging voltage, over heat, low battery, fully-charged, AC or USB charger plugged in etc. These properties are already available on these major mobile OSs, and are also valuable to developers.

What's the use case?

Received on Monday, 19 March 2012 11:08:03 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 19:32:35 UTC