diff options
-rw-r--r-- | kvision-modules/kvision-cordova/src/main/kotlin/pl/treksoft/kvision/cordova/Battery.kt | 13 |
1 files changed, 13 insertions, 0 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 84a7eb2e..656a519a 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 @@ -23,6 +23,8 @@ package pl.treksoft.kvision.cordova import kotlin.browser.window +import kotlin.coroutines.resume +import kotlin.coroutines.suspendCoroutine /** * Battery status. @@ -57,4 +59,15 @@ object Battery { }, false) } } + + /** + * Get battery status. + */ + suspend fun getStatus(): BatteryStatus { + return suspendCoroutine { continuation -> + addStatusListener(Battery.BatteryEvent.BATTERY_STATUS) { status -> + continuation.resume(status) + } + } + } } |