diff options
Diffstat (limited to 'kvision-modules/kvision-cordova')
-rw-r--r-- | kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt b/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt index 5d9b8e93..84a7eb2e 100644 --- a/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt +++ b/kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt @@ -25,15 +25,6 @@ package pl.treksoft.kvision.cordova import kotlin.browser.window /** - * Battery status event types. - */ -enum class BatteryEvent(internal val type: String) { - BATTERY_STATUS("batterystatus"), - BATTERY_LOW("batterylow"), - BATTERY_CRITICAL("batterycritical") -} - -/** * Battery status. */ external class BatteryStatus { @@ -42,13 +33,28 @@ external class BatteryStatus { } /** - * Add listeners for battery status Cordova events. + * Main object for Cordova battery. */ -fun addBatteryStatusListener(event: BatteryEvent, listener: (BatteryStatus) -> Unit) { - addDeviceReadyListener { - window.addEventListener(event.type, { status -> - @Suppress("UnsafeCastFromDynamic") - listener(status.asDynamic()) - }, false) +object Battery { + + /** + * Battery status event types. + */ + enum class BatteryEvent(internal val type: String) { + BATTERY_STATUS("batterystatus"), + BATTERY_LOW("batterylow"), + BATTERY_CRITICAL("batterycritical") + } + + /** + * Add listeners for battery status Cordova events. + */ + fun addStatusListener(event: BatteryEvent, listener: (BatteryStatus) -> Unit) { + addDeviceReadyListener { + window.addEventListener(event.type, { status -> + @Suppress("UnsafeCastFromDynamic") + listener(status.asDynamic()) + }, false) + } } } |