forked from jerrod-lankford/HAGearS3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lowBatteryCheck.js
64 lines (56 loc) · 1.26 KB
/
lowBatteryCheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(function () {
var systeminfo = {
systeminfo: null,
lowThreshold: 0.04,
listenBatteryLowState: function () {
var self = this;
try {
this.systeminfo.addPropertyValueChangeListener(
"BATTERY",
function change(battery) {
if (!battery.isCharging) {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
}
},
{
lowThreshold: self.lowThreshold
},
function onError(error) {
console.warn("An error occurred " + error.message);
}
);
} catch (ignore) {
}
},
checkBatteryLowState: function () {
var self = this;
try {
this.systeminfo.getPropertyValue(
"BATTERY",
function (battery) {
if (battery.level < self.lowThreshold && !battery.isCharging) {
try {
tizen.application.getCurrentApplication().exit();
} catch (ignore) {
}
}
},
null);
} catch (ignore) {
}
},
init: function () {
if (typeof tizen === "object" && typeof tizen.systeminfo === "object") {
this.systeminfo = tizen.systeminfo;
this.checkBatteryLowState();
this.listenBatteryLowState();
} else {
console.warn("tizen.systeminfo is not available.");
}
}
};
systeminfo.init();
}());