CB-6721 ignore null values if previous value was not null
diff --git a/www/battery.js b/www/battery.js
index ec21a96..1c6c6ab 100644
--- a/www/battery.js
+++ b/www/battery.js
@@ -70,25 +70,29 @@
Battery.prototype._status = function (info) {
if (info) {
- var me = battery;
- if (me._level !== info.level || me._isPlugged !== info.isPlugged) {
+ if (battery._level !== info.level || battery._isPlugged !== info.isPlugged) {
+
+ if(info.level == null && battery._level != null) {
+ return; // special case where callback is called because we stopped listening to the native side.
+ }
+
// Something changed. Fire batterystatus event
cordova.fireWindowEvent("batterystatus", info);
if (!info.isPlugged) { // do not fire low/critical if we are charging. issue: CB-4520
// note the following are NOT exact checks, as we want to catch a transition from
// above the threshold to below. issue: CB-4519
- if (me._level > STATUS_CRITICAL && info.level <= STATUS_CRITICAL) {
+ if (battery._level > STATUS_CRITICAL && info.level <= STATUS_CRITICAL) {
// Fire critical battery event
cordova.fireWindowEvent("batterycritical", info);
}
- else if (me._level > STATUS_LOW && info.level <= STATUS_LOW) {
+ else if (battery._level > STATUS_LOW && info.level <= STATUS_LOW) {
// Fire low battery event
cordova.fireWindowEvent("batterylow", info);
}
}
- me._level = info.level;
- me._isPlugged = info.isPlugged;
+ battery._level = info.level;
+ battery._isPlugged = info.isPlugged;
}
}
};