battery() improved detection (additional batteries windows)

This commit is contained in:
Sebastian Hildebrandt 2021-06-09 11:41:51 +02:00
parent b120e27c72
commit ac828716f7
6 changed files with 35 additions and 7 deletions

View File

@ -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) |

View File

@ -226,6 +226,16 @@
<td></td>
<td>battery serial</td>
</tr>
<tr>
<td></td>
<td>additionalBatteries[]</td>
<td></td>
<td></td>
<td></td>
<td>X</td>
<td></td>
<td>array of additional batteries</td>
</tr>
<tr class="example">
<td></td>
<td colspan="7">

View File

@ -56,6 +56,11 @@
</tr>
</thead>
<tbody>
<tr>
<th scope="row">5.7.6</th>
<td>2021-06-09</td>
<td><span class="code">battery()</span> improved detection (additional batteries windows)</td>
</tr>
<tr>
<th scope="row">5.7.5</th>
<td>2021-06-08</td>

View File

@ -170,7 +170,7 @@
<img class="logo" src="assets/logo.png">
<div class="title">systeminformation</div>
<div class="subtitle"><span id="typed"></span>&nbsp;</div>
<div class="version">New Version: <span id="version">5.7.5</span></div>
<div class="version">New Version: <span id="version">5.7.6</span></div>
<button class="btn btn-light" onclick="location.href='https://github.com/sebhildebrandt/systeminformation'">View on Github <i class=" fab fa-github"></i></button>
</div>
<div class="down">

View File

@ -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);

1
lib/index.d.ts vendored
View File

@ -284,6 +284,7 @@ export namespace Systeminformation {
model: string;
manufacturer: string;
serial: string;
additionalBatteries?: BatteryData[];
}
interface GraphicsData {