Mint wrapper for the browser BatteryManager API
The API is split into two parts, the Battery
module and the Provider.Battery
provider.
The Battery.Provider
provides change events to the subscriber. Events will fire when charging
, chargingTime
, dischargingTime
, or level
values change.
Example of using the provider
component Main {
state level = 0
use Provider.Battery {
changes:
(
isCharging : Bool,
chargingTime : Number,
dischargingTime : Number,
level : Number
) : Promise(Void) {
next { level: level }
}
}
fun render : Html {
<div>"#{level}"</div>
}
}
The Battery
module provides direct access to the Battery information.
All functions return a promise, because the underlying browser API to retrieve the BatteryManager
with window.navigator.getBattery()
returns a promise.
-
get()
- Retrieves the underlyingBatteryManager
-
isCharging()
- Returns whether the device is currently charging -
chargingTime()
- Returns the time left in seconds to fully charge -
dischargingTime()
- Returns the time left in seconds to fully discharge -
level()
- Returns the current battery level
Example using the Battery
module
component Main {
state level = 0
fun componentDidMount {
let level =
await Battery.level()
next { level: level }
}
fun render : Html {
<div>"#{level}"</div>
}
}