cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject git commit: CB-4519, CB-4520 low+critical weren't firing when level went from 21->19, and were when level went 19->20
Date Thu, 15 May 2014 00:12:39 GMT
Repository: cordova-plugin-battery-status
Updated Branches:
  refs/heads/master d38f0ab55 -> 9821813a4


CB-4519, CB-4520 low+critical weren't firing when level went from 21->19, and were when
level went 19->20


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/commit/9821813a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/9821813a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/9821813a

Branch: refs/heads/master
Commit: 9821813a4ed4d1cc9af1341763e0adc9d8a0a12d
Parents: d38f0ab
Author: Jesse MacFadyen <purplecabbage@gmail.com>
Authored: Wed May 14 17:12:03 2014 -0700
Committer: Jesse MacFadyen <purplecabbage@gmail.com>
Committed: Wed May 14 17:12:03 2014 -0700

----------------------------------------------------------------------
 www/battery.js | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/9821813a/www/battery.js
----------------------------------------------------------------------
diff --git a/www/battery.js b/www/battery.js
index 1b012ab..32ea1f4 100644
--- a/www/battery.js
+++ b/www/battery.js
@@ -64,25 +64,28 @@ Battery.onHasSubscribersChange = function() {
  *
  * @param {Object} info            keys: level, isPlugged
  */
-Battery.prototype._status = function(info) {
+Battery.prototype._status = function (info) {
+
     if (info) {
         var me = battery;
-    var level = info.level;
-        if (me._level !== level || me._isPlugged !== info.isPlugged) {
-            // Fire batterystatus event
+        if (me._level !== info.level || me._isPlugged !== info.isPlugged) {
+            // Something changed. Fire batterystatus event
             cordova.fireWindowEvent("batterystatus", info);
 
-            // Fire low battery event
-            if (level === 20 || level === 5) {
-                if (level === 20) {
+            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 {
+                else if (me._level > 5 && info.level <= 5) { 
+                    // Fire critical battery event
                     cordova.fireWindowEvent("batterycritical", info);
                 }
             }
         }
-        me._level = level;
+        me._level = info.level;
         me._isPlugged = info.isPlugged;
     }
 };
@@ -97,3 +100,4 @@ Battery.prototype._error = function(e) {
 var battery = new Battery();
 
 module.exports = battery;
+


Mime
View raw message