added battery().acconnected
This commit is contained in:
+8
-2
@@ -38,7 +38,8 @@ module.exports = function (callback) {
|
||||
ischarging: false,
|
||||
maxcapacity: 0,
|
||||
currentcapacity: 0,
|
||||
percent: 0
|
||||
percent: 0,
|
||||
acconnected: true
|
||||
};
|
||||
|
||||
if (_linux) {
|
||||
@@ -53,6 +54,7 @@ module.exports = function (callback) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
if (lines.length > 0 && lines[0]) result.ischarging = (lines[0].trim().toLowerCase() === 'charging');
|
||||
result.acconnected = result.ischarging;
|
||||
}
|
||||
exec('cat ' + battery_path + 'cyclec_ount', function (error, stdout) {
|
||||
if (!error) {
|
||||
@@ -92,6 +94,7 @@ module.exports = function (callback) {
|
||||
result.hasbattery = (batteries > 0);
|
||||
result.cyclecount = -1;
|
||||
result.ischarging = util.getValue(lines, 'hw.acpi.acline') !== '1';
|
||||
result.acconnected = result.ischarging;
|
||||
result.maxcapacity = -1;
|
||||
result.currentcapacity = -1;
|
||||
result.percent = batteries ? percent : -1;
|
||||
@@ -117,9 +120,11 @@ module.exports = function (callback) {
|
||||
}
|
||||
}
|
||||
if (parts && parts[1]) {
|
||||
result.ischarging = !(parts[1].trim() === 'charged' || parts[1].trim() === 'discharging');
|
||||
result.ischarging = (parts[1].trim() === 'charging');
|
||||
result.acconnected = (parts[1].trim() !== 'discharging');
|
||||
} else {
|
||||
result.ischarging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes';
|
||||
result.acconnected = result.ischarging;
|
||||
}
|
||||
if (result.maxcapacity && result.currentcapacity) {
|
||||
result.hasbattery = true;
|
||||
@@ -142,6 +147,7 @@ module.exports = function (callback) {
|
||||
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0);
|
||||
result.currentcapacity = parseInt(result.maxcapacity * result.percent / 100);
|
||||
result.ischarging = (status >= 6 && status <= 9) || (!(status === 3) && !(status === 1) && result.percent < 100);
|
||||
result.acconnected = result.ischarging;
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
|
||||
Reference in New Issue
Block a user