Skip to content
Permalink
Browse files
CB-6721 ignore null values if previous value was not null
  • Loading branch information
purplecabbage committed May 21, 2014
1 parent 8f8c92a commit b48708e7f733fc5612559120d2f0587b70ad0a82
Showing 1 changed file with 10 additions and 6 deletions.
@@ -70,25 +70,29 @@ Battery.onHasSubscribersChange = function() {
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;
}
}
};

0 comments on commit b48708e

Please sign in to comment.