Skip to content
Permalink
Browse files
CB-6721 Test for batterycritical change before batterylow change
  • Loading branch information
purplecabbage committed May 20, 2014
1 parent dbdcbeb commit 8f8c92a056c6ef08cd2580270db7644543342156
Showing 1 changed file with 10 additions and 7 deletions.
@@ -32,6 +32,9 @@ function handlers() {
battery.channels.batterycritical.numHandlers;
}

var STATUS_CRITICAL = 5;
var STATUS_LOW = 20;

var Battery = function() {
this._level = null;
this._isPlugged = null;
@@ -75,18 +78,18 @@ Battery.prototype._status = function (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 > 20 && info.level <= 20) {
// Fire low battery event
cordova.fireWindowEvent("batterylow", info);
}
else if (me._level > 5 && info.level <= 5) {
if (me._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) {
// Fire low battery event
cordova.fireWindowEvent("batterylow", info);
}
}
me._level = info.level;
me._isPlugged = info.isPlugged;
}
me._level = info.level;
me._isPlugged = info.isPlugged;
}
};

0 comments on commit 8f8c92a

Please sign in to comment.