systeminformation 5.28.7 → 5.28.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/battery.js +125 -107
- package/lib/bluetooth.js +111 -37
- package/package.json +1 -1
package/lib/battery.js
CHANGED
|
@@ -17,19 +17,20 @@ const exec = require('child_process').exec;
|
|
|
17
17
|
const fs = require('fs');
|
|
18
18
|
const util = require('./util');
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const _platform = process.platform;
|
|
21
21
|
|
|
22
|
-
const _linux =
|
|
23
|
-
const _darwin =
|
|
24
|
-
const _windows =
|
|
25
|
-
const _freebsd =
|
|
26
|
-
const _openbsd =
|
|
27
|
-
const _netbsd =
|
|
28
|
-
const _sunos =
|
|
22
|
+
const _linux = _platform === 'linux' || _platform === 'android';
|
|
23
|
+
const _darwin = _platform === 'darwin';
|
|
24
|
+
const _windows = _platform === 'win32';
|
|
25
|
+
const _freebsd = _platform === 'freebsd';
|
|
26
|
+
const _openbsd = _platform === 'openbsd';
|
|
27
|
+
const _netbsd = _platform === 'netbsd';
|
|
28
|
+
const _sunos = _platform === 'sunos';
|
|
29
29
|
|
|
30
30
|
function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
|
|
31
31
|
const result = {};
|
|
32
|
-
let status = util.getValue(lines, 'BatteryStatus', ':').trim();
|
|
32
|
+
let status = parseInt(util.getValue(lines, 'BatteryStatus', ':').trim(), 10) || 0;
|
|
33
|
+
// let status = util.getValue(lines, 'BatteryStatus', ':').trim();
|
|
33
34
|
// 1 = "Discharging"
|
|
34
35
|
// 2 = "On A/C"
|
|
35
36
|
// 3 = "Fully Charged"
|
|
@@ -47,11 +48,11 @@ function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
|
|
|
47
48
|
result.hasBattery = true;
|
|
48
49
|
result.maxCapacity = fullChargeCapacity || parseInt(util.getValue(lines, 'DesignCapacity', ':') || 0);
|
|
49
50
|
result.designedCapacity = parseInt(util.getValue(lines, 'DesignCapacity', ':') || designedCapacity);
|
|
50
|
-
result.voltage = parseInt(util.getValue(lines, 'DesignVoltage', ':') || 0) / 1000
|
|
51
|
+
result.voltage = (parseInt(util.getValue(lines, 'DesignVoltage', ':'), 10) || 0) / 1000;
|
|
51
52
|
result.capacityUnit = 'mWh';
|
|
52
|
-
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', ':') || 0
|
|
53
|
-
result.currentCapacity = parseInt(result.maxCapacity * result.percent / 100);
|
|
54
|
-
result.isCharging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (
|
|
53
|
+
result.percent = parseInt(util.getValue(lines, 'EstimatedChargeRemaining', ':'), 10) || 0;
|
|
54
|
+
result.currentCapacity = parseInt((result.maxCapacity * result.percent) / 100);
|
|
55
|
+
result.isCharging = (statusValue >= 6 && statusValue <= 9) || statusValue === 11 || (statusValue !== 3 && statusValue !== 1 && result.percent < 100);
|
|
55
56
|
result.acConnected = result.isCharging || statusValue === 2;
|
|
56
57
|
result.model = util.getValue(lines, 'DeviceID', ':');
|
|
57
58
|
} else {
|
|
@@ -61,9 +62,8 @@ function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
|
|
|
61
62
|
return result;
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
module.exports =
|
|
65
|
-
|
|
66
|
-
return new Promise((resolve) => {
|
|
65
|
+
module.exports = (callback) =>
|
|
66
|
+
new Promise((resolve) => {
|
|
67
67
|
process.nextTick(() => {
|
|
68
68
|
let result = {
|
|
69
69
|
hasBattery: false,
|
|
@@ -105,22 +105,24 @@ module.exports = function (callback) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (battery_path) {
|
|
108
|
-
fs.readFile(battery_path + 'uevent',
|
|
108
|
+
fs.readFile(battery_path + 'uevent', (error, stdout) => {
|
|
109
109
|
if (!error) {
|
|
110
110
|
let lines = stdout.toString().split('\n');
|
|
111
111
|
|
|
112
|
-
result.isCharging =
|
|
112
|
+
result.isCharging = util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging';
|
|
113
113
|
result.acConnected = acConnected || result.isCharging;
|
|
114
114
|
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
|
|
115
115
|
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
|
116
116
|
result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
|
117
|
-
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0 * (result.voltage || 1));
|
|
117
|
+
result.maxCapacity = Math.round((parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0) * (result.voltage || 1));
|
|
118
118
|
const desingedMinVoltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN', '='), 10) / 1000000.0;
|
|
119
|
-
result.designedCapacity = Math.round(
|
|
120
|
-
|
|
119
|
+
result.designedCapacity = Math.round(
|
|
120
|
+
(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '=', true, true), 10) / 1000.0) * (desingedMinVoltage || result.voltage || 1)
|
|
121
|
+
);
|
|
122
|
+
result.currentCapacity = Math.round((parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0) * (result.voltage || 1));
|
|
121
123
|
if (!result.maxCapacity) {
|
|
122
124
|
result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '=', true, true), 10) / 1000.0;
|
|
123
|
-
result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '=', true, true), 10) / 1000.0 | result.maxCapacity;
|
|
125
|
+
result.designedCapacity = (parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '=', true, true), 10) / 1000.0) | result.maxCapacity;
|
|
124
126
|
result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
|
|
125
127
|
}
|
|
126
128
|
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
|
|
@@ -133,41 +135,47 @@ module.exports = function (callback) {
|
|
|
133
135
|
if (result.maxCapacity && result.currentCapacity) {
|
|
134
136
|
result.hasBattery = true;
|
|
135
137
|
if (!percent) {
|
|
136
|
-
result.percent = 100.0 * result.currentCapacity / result.maxCapacity;
|
|
138
|
+
result.percent = (100.0 * result.currentCapacity) / result.maxCapacity;
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
if (result.isCharging) {
|
|
140
142
|
result.hasBattery = true;
|
|
141
143
|
}
|
|
142
144
|
if (energy && power) {
|
|
143
|
-
result.timeRemaining = Math.floor(energy / power * 60);
|
|
145
|
+
result.timeRemaining = Math.floor((energy / power) * 60);
|
|
144
146
|
} else if (current && charge) {
|
|
145
|
-
result.timeRemaining = Math.floor(charge / current * 60);
|
|
147
|
+
result.timeRemaining = Math.floor((charge / current) * 60);
|
|
146
148
|
} else if (current && result.currentCapacity) {
|
|
147
|
-
result.timeRemaining = Math.floor(result.currentCapacity / current * 60);
|
|
149
|
+
result.timeRemaining = Math.floor((result.currentCapacity / current) * 60);
|
|
148
150
|
}
|
|
149
151
|
result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
|
|
150
152
|
result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');
|
|
151
153
|
result.manufacturer = util.getValue(lines, 'POWER_SUPPLY_MANUFACTURER', '=');
|
|
152
154
|
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
|
|
153
|
-
if (callback) {
|
|
155
|
+
if (callback) {
|
|
156
|
+
callback(result);
|
|
157
|
+
}
|
|
154
158
|
resolve(result);
|
|
155
159
|
} else {
|
|
156
|
-
if (callback) {
|
|
160
|
+
if (callback) {
|
|
161
|
+
callback(result);
|
|
162
|
+
}
|
|
157
163
|
resolve(result);
|
|
158
164
|
}
|
|
159
165
|
});
|
|
160
166
|
} else {
|
|
161
|
-
if (callback) {
|
|
167
|
+
if (callback) {
|
|
168
|
+
callback(result);
|
|
169
|
+
}
|
|
162
170
|
resolve(result);
|
|
163
171
|
}
|
|
164
172
|
}
|
|
165
173
|
if (_freebsd || _openbsd || _netbsd) {
|
|
166
|
-
exec('sysctl -i hw.acpi.battery hw.acpi.acline',
|
|
174
|
+
exec('sysctl -i hw.acpi.battery hw.acpi.acline', (error, stdout) => {
|
|
167
175
|
let lines = stdout.toString().split('\n');
|
|
168
176
|
const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10);
|
|
169
177
|
const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10);
|
|
170
|
-
result.hasBattery =
|
|
178
|
+
result.hasBattery = batteries > 0;
|
|
171
179
|
result.cycleCount = null;
|
|
172
180
|
result.isCharging = util.getValue(lines, 'hw.acpi.acline') !== '1';
|
|
173
181
|
result.acConnected = result.isCharging;
|
|
@@ -175,55 +183,64 @@ module.exports = function (callback) {
|
|
|
175
183
|
result.currentCapacity = null;
|
|
176
184
|
result.capacityUnit = 'unknown';
|
|
177
185
|
result.percent = batteries ? percent : null;
|
|
178
|
-
if (callback) {
|
|
186
|
+
if (callback) {
|
|
187
|
+
callback(result);
|
|
188
|
+
}
|
|
179
189
|
resolve(result);
|
|
180
190
|
});
|
|
181
191
|
}
|
|
182
192
|
|
|
183
193
|
if (_darwin) {
|
|
184
|
-
exec(
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
let
|
|
201
|
-
if (
|
|
202
|
-
|
|
194
|
+
exec(
|
|
195
|
+
'ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|DeviceName|BatterySerialNumber|Serial|TimeRemaining|Voltage"; pmset -g batt | grep %',
|
|
196
|
+
(error, stdout) => {
|
|
197
|
+
if (stdout) {
|
|
198
|
+
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
|
|
199
|
+
result.cycleCount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
|
|
200
|
+
result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
|
|
201
|
+
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
|
202
|
+
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawmaxcapacity', '='), 10) * (result.voltage || 1));
|
|
203
|
+
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'applerawcurrentcapacity', '='), 10) * (result.voltage || 1));
|
|
204
|
+
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1));
|
|
205
|
+
result.manufacturer = 'Apple';
|
|
206
|
+
result.serial = util.getValue(lines, 'BatterySerialNumber', '=') || util.getValue(lines, 'Serial', '=');
|
|
207
|
+
result.model = util.getValue(lines, 'DeviceName', '=');
|
|
208
|
+
let percent = null;
|
|
209
|
+
const line = util.getValue(lines, 'internal', 'Battery');
|
|
210
|
+
let parts = line.split(';');
|
|
211
|
+
if (parts && parts[0]) {
|
|
212
|
+
let parts2 = parts[0].split('\t');
|
|
213
|
+
if (parts2 && parts2[1]) {
|
|
214
|
+
percent = parseFloat(parts2[1].trim().replace(/%/g, ''));
|
|
215
|
+
}
|
|
203
216
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
217
|
+
if (parts && parts[1]) {
|
|
218
|
+
result.isCharging = parts[1].trim() === 'charging';
|
|
219
|
+
result.acConnected = parts[1].trim() !== 'discharging';
|
|
220
|
+
} else {
|
|
221
|
+
result.isCharging = util.getValue(lines, 'ischarging', '=').toLowerCase() === 'yes';
|
|
222
|
+
result.acConnected = result.isCharging;
|
|
223
|
+
}
|
|
224
|
+
if (result.maxCapacity && result.currentCapacity) {
|
|
225
|
+
result.hasBattery = true;
|
|
226
|
+
result.type = 'Li-ion';
|
|
227
|
+
result.percent = percent !== null ? percent : Math.round((100.0 * result.currentCapacity) / result.maxCapacity);
|
|
228
|
+
if (!result.isCharging) {
|
|
229
|
+
result.timeRemaining = parseInt('0' + util.getValue(lines, 'TimeRemaining', '='), 10);
|
|
230
|
+
}
|
|
218
231
|
}
|
|
219
232
|
}
|
|
233
|
+
if (callback) {
|
|
234
|
+
callback(result);
|
|
235
|
+
}
|
|
236
|
+
resolve(result);
|
|
220
237
|
}
|
|
221
|
-
|
|
222
|
-
resolve(result);
|
|
223
|
-
});
|
|
238
|
+
);
|
|
224
239
|
}
|
|
225
240
|
if (_sunos) {
|
|
226
|
-
if (callback) {
|
|
241
|
+
if (callback) {
|
|
242
|
+
callback(result);
|
|
243
|
+
}
|
|
227
244
|
resolve(result);
|
|
228
245
|
}
|
|
229
246
|
if (_windows) {
|
|
@@ -232,30 +249,30 @@ module.exports = function (callback) {
|
|
|
232
249
|
workload.push(util.powerShell('Get-CimInstance Win32_Battery | select BatteryStatus, DesignCapacity, DesignVoltage, EstimatedChargeRemaining, DeviceID | fl'));
|
|
233
250
|
workload.push(util.powerShell('(Get-WmiObject -Class BatteryStaticData -Namespace ROOT/WMI).DesignedCapacity'));
|
|
234
251
|
workload.push(util.powerShell('(Get-CimInstance -Class BatteryFullChargedCapacity -Namespace ROOT/WMI).FullChargedCapacity'));
|
|
235
|
-
util.promiseAll(
|
|
236
|
-
workload
|
|
237
|
-
).then((data) => {
|
|
252
|
+
util.promiseAll(workload).then((data) => {
|
|
238
253
|
if (data) {
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
const hasValue = value => /\S/.test(value);
|
|
254
|
+
const parts = data.results[0].split(/\n\s*\n/);
|
|
255
|
+
const batteries = [];
|
|
256
|
+
const hasValue = (value) => /\S/.test(value);
|
|
242
257
|
for (let i = 0; i < parts.length; i++) {
|
|
243
|
-
if (hasValue(parts[i]) && (!batteries.length || !hasValue(parts[i - 1]))) {
|
|
244
|
-
|
|
245
|
-
}
|
|
258
|
+
// if (hasValue(parts[i]) && (!batteries.length || !hasValue(parts[i - 1]))) {
|
|
259
|
+
// batteries.push([]);
|
|
260
|
+
// }
|
|
246
261
|
if (hasValue(parts[i])) {
|
|
247
|
-
batteries[batteries.length - 1].push(parts[i]);
|
|
262
|
+
// batteries[batteries.length - 1].push(parts[i]);
|
|
263
|
+
batteries.push(parts[i]);
|
|
248
264
|
}
|
|
249
265
|
}
|
|
250
|
-
|
|
251
|
-
|
|
266
|
+
const designCapacities = data.results[1].split('\r\n').filter((e) => e);
|
|
267
|
+
const fullChargeCapacities = data.results[2].split('\r\n').filter((e) => e);
|
|
252
268
|
if (batteries.length) {
|
|
253
269
|
let first = false;
|
|
254
|
-
|
|
270
|
+
const additionalBatteries = [];
|
|
255
271
|
for (let i = 0; i < batteries.length; i++) {
|
|
256
|
-
let lines = batteries[i][0].split('\r\n');
|
|
257
|
-
const
|
|
258
|
-
const
|
|
272
|
+
// let lines = batteries[i][0].split('\r\n');
|
|
273
|
+
const lines = batteries[i].split('\r\n');
|
|
274
|
+
const designedCapacity = designCapacities && designCapacities.length >= i + 1 && designCapacities[i] ? util.toInt(designCapacities[i]) : 0;
|
|
275
|
+
const fullChargeCapacity = fullChargeCapacities && fullChargeCapacities.length >= i + 1 && fullChargeCapacities[i] ? util.toInt(fullChargeCapacities[i]) : 0;
|
|
259
276
|
const parsed = parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity);
|
|
260
277
|
if (!first && parsed.status > 0 && parsed.status !== 10) {
|
|
261
278
|
result.hasBattery = parsed.hasBattery;
|
|
@@ -270,24 +287,22 @@ module.exports = function (callback) {
|
|
|
270
287
|
result.model = parsed.model;
|
|
271
288
|
first = true;
|
|
272
289
|
} else if (parsed.status !== -1) {
|
|
273
|
-
additionalBatteries.push(
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
}
|
|
290
|
-
);
|
|
290
|
+
additionalBatteries.push({
|
|
291
|
+
hasBattery: parsed.hasBattery,
|
|
292
|
+
maxCapacity: parsed.maxCapacity,
|
|
293
|
+
designedCapacity: parsed.designedCapacity,
|
|
294
|
+
voltage: parsed.voltage,
|
|
295
|
+
capacityUnit: parsed.capacityUnit,
|
|
296
|
+
percent: parsed.percent,
|
|
297
|
+
currentCapacity: parsed.currentCapacity,
|
|
298
|
+
isCharging: parsed.isCharging,
|
|
299
|
+
timeRemaining: null,
|
|
300
|
+
acConnected: parsed.acConnected,
|
|
301
|
+
model: parsed.model,
|
|
302
|
+
type: '',
|
|
303
|
+
manufacturer: '',
|
|
304
|
+
serial: ''
|
|
305
|
+
});
|
|
291
306
|
}
|
|
292
307
|
}
|
|
293
308
|
if (!first && additionalBatteries.length) {
|
|
@@ -299,14 +314,17 @@ module.exports = function (callback) {
|
|
|
299
314
|
}
|
|
300
315
|
}
|
|
301
316
|
}
|
|
302
|
-
if (callback) {
|
|
317
|
+
if (callback) {
|
|
318
|
+
callback(result);
|
|
319
|
+
}
|
|
303
320
|
resolve(result);
|
|
304
321
|
});
|
|
305
|
-
} catch
|
|
306
|
-
if (callback) {
|
|
322
|
+
} catch {
|
|
323
|
+
if (callback) {
|
|
324
|
+
callback(result);
|
|
325
|
+
}
|
|
307
326
|
resolve(result);
|
|
308
327
|
}
|
|
309
328
|
}
|
|
310
329
|
});
|
|
311
330
|
});
|
|
312
|
-
};
|
package/lib/bluetooth.js
CHANGED
|
@@ -22,28 +22,59 @@ const fs = require('fs');
|
|
|
22
22
|
|
|
23
23
|
let _platform = process.platform;
|
|
24
24
|
|
|
25
|
-
const _linux =
|
|
26
|
-
const _darwin =
|
|
27
|
-
const _windows =
|
|
28
|
-
const _freebsd =
|
|
29
|
-
const _openbsd =
|
|
30
|
-
const _netbsd =
|
|
31
|
-
const _sunos =
|
|
25
|
+
const _linux = _platform === 'linux' || _platform === 'android';
|
|
26
|
+
const _darwin = _platform === 'darwin';
|
|
27
|
+
const _windows = _platform === 'win32';
|
|
28
|
+
const _freebsd = _platform === 'freebsd';
|
|
29
|
+
const _openbsd = _platform === 'openbsd';
|
|
30
|
+
const _netbsd = _platform === 'netbsd';
|
|
31
|
+
const _sunos = _platform === 'sunos';
|
|
32
32
|
|
|
33
33
|
function parseBluetoothType(str) {
|
|
34
34
|
let result = '';
|
|
35
35
|
|
|
36
|
-
if (str.indexOf('keyboard') >= 0) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (str.indexOf('
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
if (str.indexOf('
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (str.indexOf('
|
|
46
|
-
|
|
36
|
+
if (str.indexOf('keyboard') >= 0) {
|
|
37
|
+
result = 'Keyboard';
|
|
38
|
+
}
|
|
39
|
+
if (str.indexOf('mouse') >= 0) {
|
|
40
|
+
result = 'Mouse';
|
|
41
|
+
}
|
|
42
|
+
if (str.indexOf('trackpad') >= 0) {
|
|
43
|
+
result = 'Trackpad';
|
|
44
|
+
}
|
|
45
|
+
if (str.indexOf('audio') >= 0) {
|
|
46
|
+
result = 'Audio';
|
|
47
|
+
}
|
|
48
|
+
if (str.indexOf('sound') >= 0) {
|
|
49
|
+
result = 'Audio';
|
|
50
|
+
}
|
|
51
|
+
if (str.indexOf('microph') >= 0) {
|
|
52
|
+
result = 'Microphone';
|
|
53
|
+
}
|
|
54
|
+
if (str.indexOf('speaker') >= 0) {
|
|
55
|
+
result = 'Speaker';
|
|
56
|
+
}
|
|
57
|
+
if (str.indexOf('headset') >= 0) {
|
|
58
|
+
result = 'Headset';
|
|
59
|
+
}
|
|
60
|
+
if (str.indexOf('phone') >= 0) {
|
|
61
|
+
result = 'Phone';
|
|
62
|
+
}
|
|
63
|
+
if (str.indexOf('macbook') >= 0) {
|
|
64
|
+
result = 'Computer';
|
|
65
|
+
}
|
|
66
|
+
if (str.indexOf('imac') >= 0) {
|
|
67
|
+
result = 'Computer';
|
|
68
|
+
}
|
|
69
|
+
if (str.indexOf('ipad') >= 0) {
|
|
70
|
+
result = 'Tablet';
|
|
71
|
+
}
|
|
72
|
+
if (str.indexOf('watch') >= 0) {
|
|
73
|
+
result = 'Watch';
|
|
74
|
+
}
|
|
75
|
+
if (str.indexOf('headphone') >= 0) {
|
|
76
|
+
result = 'Headset';
|
|
77
|
+
}
|
|
47
78
|
// to be continued ...
|
|
48
79
|
|
|
49
80
|
return result;
|
|
@@ -52,13 +83,27 @@ function parseBluetoothType(str) {
|
|
|
52
83
|
function parseBluetoothManufacturer(str) {
|
|
53
84
|
let result = str.split(' ')[0];
|
|
54
85
|
str = str.toLowerCase();
|
|
55
|
-
if (str.indexOf('apple') >= 0) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (str.indexOf('
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (str.indexOf('
|
|
86
|
+
if (str.indexOf('apple') >= 0) {
|
|
87
|
+
result = 'Apple';
|
|
88
|
+
}
|
|
89
|
+
if (str.indexOf('ipad') >= 0) {
|
|
90
|
+
result = 'Apple';
|
|
91
|
+
}
|
|
92
|
+
if (str.indexOf('imac') >= 0) {
|
|
93
|
+
result = 'Apple';
|
|
94
|
+
}
|
|
95
|
+
if (str.indexOf('iphone') >= 0) {
|
|
96
|
+
result = 'Apple';
|
|
97
|
+
}
|
|
98
|
+
if (str.indexOf('magic mouse') >= 0) {
|
|
99
|
+
result = 'Apple';
|
|
100
|
+
}
|
|
101
|
+
if (str.indexOf('magic track') >= 0) {
|
|
102
|
+
result = 'Apple';
|
|
103
|
+
}
|
|
104
|
+
if (str.indexOf('macbook') >= 0) {
|
|
105
|
+
result = 'Apple';
|
|
106
|
+
}
|
|
62
107
|
// to be continued ...
|
|
63
108
|
|
|
64
109
|
return result;
|
|
@@ -86,7 +131,9 @@ function parseLinuxBluetoothInfo(lines, macAddr1, macAddr2) {
|
|
|
86
131
|
|
|
87
132
|
function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {
|
|
88
133
|
const result = {};
|
|
89
|
-
const typeStr = (
|
|
134
|
+
const typeStr = (
|
|
135
|
+
(bluetoothObject.device_minorClassOfDevice_string || bluetoothObject.device_majorClassOfDevice_string || bluetoothObject.device_minorType || '') + (bluetoothObject.device_name || '')
|
|
136
|
+
).toLowerCase();
|
|
90
137
|
|
|
91
138
|
result.device = bluetoothObject.device_services || '';
|
|
92
139
|
result.name = bluetoothObject.device_name || '';
|
|
@@ -116,7 +163,6 @@ function parseWindowsBluetooth(lines) {
|
|
|
116
163
|
}
|
|
117
164
|
|
|
118
165
|
function bluetoothDevices(callback) {
|
|
119
|
-
|
|
120
166
|
return new Promise((resolve) => {
|
|
121
167
|
process.nextTick(() => {
|
|
122
168
|
let result = [];
|
|
@@ -152,11 +198,17 @@ function bluetoothDevices(callback) {
|
|
|
152
198
|
}
|
|
153
199
|
if (_darwin) {
|
|
154
200
|
let cmd = 'system_profiler SPBluetoothDataType -json';
|
|
155
|
-
exec(cmd,
|
|
201
|
+
exec(cmd, (error, stdout) => {
|
|
156
202
|
if (!error) {
|
|
157
203
|
try {
|
|
158
204
|
const outObj = JSON.parse(stdout.toString());
|
|
159
|
-
if (
|
|
205
|
+
if (
|
|
206
|
+
outObj.SPBluetoothDataType &&
|
|
207
|
+
outObj.SPBluetoothDataType.length &&
|
|
208
|
+
outObj.SPBluetoothDataType[0] &&
|
|
209
|
+
outObj.SPBluetoothDataType[0]['device_title'] &&
|
|
210
|
+
outObj.SPBluetoothDataType[0]['device_title'].length
|
|
211
|
+
) {
|
|
160
212
|
// missing: host BT Adapter macAddr ()
|
|
161
213
|
let macAddr2 = null;
|
|
162
214
|
if (outObj.SPBluetoothDataType[0]['local_device_title'] && outObj.SPBluetoothDataType[0].local_device_title.general_address) {
|
|
@@ -173,8 +225,17 @@ function bluetoothDevices(callback) {
|
|
|
173
225
|
}
|
|
174
226
|
});
|
|
175
227
|
}
|
|
176
|
-
if (
|
|
177
|
-
|
|
228
|
+
if (
|
|
229
|
+
outObj.SPBluetoothDataType &&
|
|
230
|
+
outObj.SPBluetoothDataType.length &&
|
|
231
|
+
outObj.SPBluetoothDataType[0] &&
|
|
232
|
+
outObj.SPBluetoothDataType[0]['device_connected'] &&
|
|
233
|
+
outObj.SPBluetoothDataType[0]['device_connected'].length
|
|
234
|
+
) {
|
|
235
|
+
const macAddr2 =
|
|
236
|
+
outObj.SPBluetoothDataType[0].controller_properties && outObj.SPBluetoothDataType[0].controller_properties.controller_address
|
|
237
|
+
? outObj.SPBluetoothDataType[0].controller_properties.controller_address.toLowerCase().replace(/-/g, ':')
|
|
238
|
+
: null;
|
|
178
239
|
outObj.SPBluetoothDataType[0]['device_connected'].forEach((element) => {
|
|
179
240
|
const obj = element;
|
|
180
241
|
const objKey = Object.keys(obj);
|
|
@@ -187,8 +248,17 @@ function bluetoothDevices(callback) {
|
|
|
187
248
|
}
|
|
188
249
|
});
|
|
189
250
|
}
|
|
190
|
-
if (
|
|
191
|
-
|
|
251
|
+
if (
|
|
252
|
+
outObj.SPBluetoothDataType &&
|
|
253
|
+
outObj.SPBluetoothDataType.length &&
|
|
254
|
+
outObj.SPBluetoothDataType[0] &&
|
|
255
|
+
outObj.SPBluetoothDataType[0]['device_not_connected'] &&
|
|
256
|
+
outObj.SPBluetoothDataType[0]['device_not_connected'].length
|
|
257
|
+
) {
|
|
258
|
+
const macAddr2 =
|
|
259
|
+
outObj.SPBluetoothDataType[0].controller_properties && outObj.SPBluetoothDataType[0].controller_properties.controller_address
|
|
260
|
+
? outObj.SPBluetoothDataType[0].controller_properties.controller_address.toLowerCase().replace(/-/g, ':')
|
|
261
|
+
: null;
|
|
192
262
|
outObj.SPBluetoothDataType[0]['device_not_connected'].forEach((element) => {
|
|
193
263
|
const obj = element;
|
|
194
264
|
const objKey = Object.keys(obj);
|
|
@@ -201,7 +271,7 @@ function bluetoothDevices(callback) {
|
|
|
201
271
|
}
|
|
202
272
|
});
|
|
203
273
|
}
|
|
204
|
-
} catch
|
|
274
|
+
} catch {
|
|
205
275
|
util.noop();
|
|
206
276
|
}
|
|
207
277
|
}
|
|
@@ -212,12 +282,16 @@ function bluetoothDevices(callback) {
|
|
|
212
282
|
});
|
|
213
283
|
}
|
|
214
284
|
if (_windows) {
|
|
215
|
-
util.powerShell('Get-CimInstance Win32_PNPEntity | select PNPClass, Name, Manufacturer | fl').then((stdout, error) => {
|
|
285
|
+
util.powerShell('Get-CimInstance Win32_PNPEntity | select PNPClass, Name, Manufacturer, Status, Service, ConfigManagerErrorCode, Present | fl').then((stdout, error) => {
|
|
216
286
|
if (!error) {
|
|
217
287
|
const parts = stdout.toString().split(/\n\s*\n/);
|
|
218
288
|
parts.forEach((part) => {
|
|
219
|
-
|
|
220
|
-
|
|
289
|
+
const lines = part.split('\n');
|
|
290
|
+
const service = util.getValue(lines, 'Service', ':');
|
|
291
|
+
const errorCode = util.getValue(lines, 'ConfigManagerErrorCode', ':');
|
|
292
|
+
const pnpClass = util.getValue(lines, 'PNPClass', ':').toLowerCase();
|
|
293
|
+
if (pnpClass === 'bluetooth' && errorCode === '0' && service === '') {
|
|
294
|
+
result.push(parseWindowsBluetooth(lines));
|
|
221
295
|
}
|
|
222
296
|
});
|
|
223
297
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "systeminformation",
|
|
3
|
-
"version": "5.28.
|
|
3
|
+
"version": "5.28.8",
|
|
4
4
|
"description": "Advanced, lightweight system and OS information library",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",
|