diff --git a/CHANGELOG.md b/CHANGELOG.md index 22ddba4..145131f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -77,6 +77,7 @@ For major (breaking) changes - **version 4, 3 and 2** - see end of page. | Version | Date | Comment | | -------------- | -------------- | -------- | +| 5.7.6 | 2021-06-09 | `battery()` improved detection (additional batteries windows) | | 5.7.5 | 2021-06-08 | `memLayout()` improved clock speed detection (windows) | | 5.7.4 | 2021-05-27 | `osInfo()`, `cpu()` improved hypervisor, virtualization detection (windows) | | 5.7.3 | 2021-05-26 | `osInfo()` improved UEFI detection (windows) | diff --git a/docs/battery.html b/docs/battery.html index 9ebed0b..d912070 100644 --- a/docs/battery.html +++ b/docs/battery.html @@ -226,6 +226,16 @@ battery serial + + + additionalBatteries[] + + + + X + + array of additional batteries + diff --git a/docs/history.html b/docs/history.html index b5fea79..fa11c5f 100644 --- a/docs/history.html +++ b/docs/history.html @@ -56,6 +56,11 @@ + + 5.7.6 + 2021-06-09 + battery() improved detection (additional batteries windows) + 5.7.5 2021-06-08 diff --git a/docs/index.html b/docs/index.html index 87c1199..7d3caf6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -170,7 +170,7 @@
systeminformation
 
-
New Version: 5.7.5
+
New Version: 5.7.6
diff --git a/lib/battery.js b/lib/battery.js index c01eb00..7c049e8 100644 --- a/lib/battery.js +++ b/lib/battery.js @@ -41,7 +41,7 @@ function parseWinBatteryPart(lines, designCapacity, fullChargeCapacity) { // 9 = "Charging Critical" // 10 = "Undefined" // 11 = "Partially Charged" - if (lines.join('').toLowerCase().indexOf('BatteryStatus') >= 0) { + if (status >= 0) { const statusValue = status ? parseInt(status) : 0; result.status = statusValue; result.hasBattery = true; @@ -50,7 +50,7 @@ function parseWinBatteryPart(lines, designCapacity, fullChargeCapacity) { result.voltage = parseInt(util.getValue(lines, 'DesignVoltage', '=') || 0) / 1000.0; result.capacityUnit = 'mWh'; result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', '=') || 0); - result.currentCapacity = parseInt(result.maxcapacity * result.percent / 100); + result.currentCapacity = parseInt(result.maxCapacity * result.percent / 100); result.isCharging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (!(statusValue === 3) && !(statusValue === 1) && result.percent < 100); result.acConnected = result.ischarging || statusValue === 2; result.model = util.getValue(lines, 'DeviceID', '='); @@ -217,14 +217,25 @@ module.exports = function (callback) { workload ).then(data => { if (data) { - let parts = data.results[0].split(/\n\s*\n/); + // let parts = data.results[0].split(/\n\s*\n/); + let parts = data.results[0].split('\r\n'); + let batteries = []; + for (let i = 0; i < parts.length; i++) { + const hasValue = value => /\S/.test(value); + if (hasValue(parts[i]) && (!batteries.length || !hasValue(parts[i - 1]))) { + batteries.push([]); + } + if (hasValue(parts[i])) { + batteries[batteries.length - 1].push(parts[i]); + } + } let designCapacities = data.results[1].split('\r\n'); let fullChargeCapacities = data.results[2].split('\r\n'); - if (parts && parts.length) { + if (batteries && batteries.length) { let first = false; let additionalBatteries = []; - for (let i = 0; i < parts.length; i++) { - let lines = parts[i].split('\r\n'); + for (let i = 0; i < batteries.length; i++) { + let lines = batteries[i]; const designCapacity = designCapacities && designCapacities.length >= (i + 1) && designCapacities[i] ? util.toInt(designCapacities[i]) : 0; const fullChargeCapacity = fullChargeCapacities && fullChargeCapacities.length >= (i + 1) && fullChargeCapacities[i] ? util.toInt(fullChargeCapacities[i]) : 0; const parsed = parseWinBatteryPart(lines, designCapacity, fullChargeCapacity); diff --git a/lib/index.d.ts b/lib/index.d.ts index e72dc39..eeb620b 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -284,6 +284,7 @@ export namespace Systeminformation { model: string; manufacturer: string; serial: string; + additionalBatteries?: BatteryData[]; } interface GraphicsData {