You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2014/05/21 21:38:56 UTC
git commit: CB-6721 ignore null values if previous value was not null
Repository: cordova-plugin-battery-status
Updated Branches:
refs/heads/master 8f8c92a05 -> b48708e7f
CB-6721 ignore null values if previous value was not null
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/b48708e7
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/tree/b48708e7
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/diff/b48708e7
Branch: refs/heads/master
Commit: b48708e7f733fc5612559120d2f0587b70ad0a82
Parents: 8f8c92a
Author: purplecabbage <pu...@gmail.com>
Authored: Wed May 21 12:24:07 2014 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Wed May 21 12:24:07 2014 -0700
----------------------------------------------------------------------
www/battery.js | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-battery-status/blob/b48708e7/www/battery.js
----------------------------------------------------------------------
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.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;
}
}
};