Re: Comments about battery status API

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?

-Anssi

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