basic android support, updated docs
This commit is contained in:
parent
23651f976e
commit
f49c39b631
@ -62,7 +62,7 @@ Lightweight collection of 50+ functions to retrieve detailed hardware, system an
|
||||
|
||||
- simple to use
|
||||
- get detailed information about system, cpu, baseboard, battery, memory, disks/filesystem, network, docker, software, services and processes
|
||||
- supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD and SunOS support
|
||||
- supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD, SunOS and Android support
|
||||
- no npm dependencies
|
||||
|
||||
**Attention**: this is a `node.js` library. It is supposed to be used as a backend/server-side library and will definitely not work within a browser.
|
||||
|
||||
@ -262,7 +262,7 @@ si.audio().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -308,7 +308,7 @@ si.battery().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -226,7 +226,7 @@ si.bluetoothDevices().then(data => console.log(data));</code></pre class="exampl
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -268,7 +268,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -110,7 +110,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -123,7 +123,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -643,7 +643,7 @@ si.cpuTemperature().then(data => console.log(data));</code></pre class="example"
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -1347,7 +1347,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -964,7 +964,7 @@ setInterval(function() {
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -402,7 +402,7 @@ si.get(valueObject).then(data => console.log(data));</code></pre class="example"
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -52,7 +52,7 @@
|
||||
<ul>
|
||||
<li>simple to use</li>
|
||||
<li>get detailed information about system, cpu, baseboard, battery, memory, disks/filesystem, network, docker, software, services and processes</li>
|
||||
<li>supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD and SunOS support</li>
|
||||
<li>supports Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD, SunOS and Android support</li>
|
||||
<li>no npm dependencies</li>
|
||||
</ul>
|
||||
|
||||
@ -166,7 +166,7 @@ async function cpuData() {
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -634,7 +634,7 @@ si.graphics().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -57,6 +57,11 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th scope="row">5.10.0</th>
|
||||
<td>2022-01-09</td>
|
||||
<td>Basic <span class="code">Android</span> support</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">5.9.18</th>
|
||||
<td>2022-01-08</td>
|
||||
@ -2533,7 +2538,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -170,7 +170,7 @@
|
||||
<img class="logo" src="assets/logo.png">
|
||||
<div class="title">systeminformation</div>
|
||||
<div class="subtitle"><span id="typed"></span> </div>
|
||||
<div class="version">New Version: <span id="version">5.9.18</span></div>
|
||||
<div class="version">New Version: <span id="version">5.10.0</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">
|
||||
@ -386,7 +386,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -124,7 +124,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -428,7 +428,7 @@ si.memLayout().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -803,7 +803,7 @@ setInterval(function() {
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -800,7 +800,7 @@ si.users().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -239,7 +239,7 @@ si.printer().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -754,7 +754,7 @@ si.services('mysql, postgres').then(data => console.log(data));</code></pre clas
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -240,7 +240,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -157,7 +157,7 @@ setTimeout(() => {
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -583,7 +583,7 @@ si.chassis().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
@ -598,4 +598,4 @@ si.chassis().then(data => console.log(data));</code></pre class="example">
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
</html>
|
||||
|
||||
@ -143,7 +143,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -274,7 +274,7 @@ si.usb().then(data => console.log(data));</code></pre class="example">
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -291,7 +291,7 @@ si.battery().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -101,7 +101,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -95,7 +95,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -584,7 +584,7 @@ si.cpuTemperature().then(data => console.log(data));</code></pre class="example"
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -1069,7 +1069,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -876,7 +876,7 @@ setInterval(function() {
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -341,7 +341,7 @@ si.get(valueObject).then(data => console.log(data));</code></pre class="example"
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -161,7 +161,7 @@ async function cpuData() {
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -537,7 +537,7 @@ si.graphics().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -2134,7 +2134,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -185,7 +185,7 @@
|
||||
<div class="row">
|
||||
<div class="col-12 sectionheader index">
|
||||
<div class="title">Overview</div>
|
||||
<div class="subtitle">Lightweight collection of 40+ functions to retrieve detailed hardware, system and OS information. For Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD and SunOS support</div>
|
||||
<div class="subtitle">Lightweight collection of 40+ functions to retrieve detailed hardware, system and OS information. For Linux, macOS, partial Windows, FreeBSD, OpenBSD, NetBSD, SunOS and Android support</div>
|
||||
<div class="npmicons">
|
||||
<a href="https://npmjs.org/package/systeminformation" rel="nofollow"><img src="https://camo.githubusercontent.com/df25636cbefadf18ca1532e3bdcd0d2794235e19/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f73797374656d696e666f726d6174696f6e2e7376673f7374796c653d666c61742d737175617265" alt="NPM Version" data-canonical-src="https://img.shields.io/npm/v/systeminformation.svg?style=flat-square" style="max-width:100%;"></a>
|
||||
<a href="https://david-dm.org/sebhildebrandt/systeminformation" rel="nofollow"><img src="https://camo.githubusercontent.com/69739c043c2be3a38545f105b89381a2a6310f59/68747470733a2f2f696d672e736869656c64732e696f2f64617669642f73656268696c64656272616e64742f73797374656d696e666f726d6174696f6e2e7376673f7374796c653d666c61742d737175617265" alt="deps status" data-canonical-src="https://img.shields.io/david/sebhildebrandt/systeminformation.svg?style=flat-square" style="max-width:100%;"></a>
|
||||
@ -350,7 +350,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -115,7 +115,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -409,7 +409,7 @@ si.memLayout().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -796,7 +796,7 @@ setInterval(function() {
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -738,7 +738,7 @@ si.users().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -734,7 +734,7 @@ si.services('mysql, postgres').then(data => console.log(data));</code></pre clas
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -231,7 +231,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -150,7 +150,7 @@ setTimeout(() => {
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -443,7 +443,7 @@ si.chassis().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -101,7 +101,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -469,7 +469,7 @@
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -246,7 +246,7 @@ si.wifiNetworks().then(data => console.log(data));</code></pre class="example">
|
||||
</div>
|
||||
<div class="col-lg-4 col-12">
|
||||
<ul class="list-unstyled">
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt, +innovations</a></li>
|
||||
<li><a href="copyright.html">Copyright & License</a></li>
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
|
||||
@ -476,7 +476,7 @@
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@ -524,7 +524,7 @@ si.wifiConnections().then(data => console.log(data));</code></pre class="example
|
||||
<li><a href="trademarks.html">Trademarks</a></li>
|
||||
<li> </li>
|
||||
<li><a href="copyright.html">Copyright & License <img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT license" /></a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2021 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">© 2022 Sebastian Hildebrandt</a></li>
|
||||
<li><a href="https://www.plus-innovations.com">+innovations GmbH</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
438
lib/audio.js
438
lib/audio.js
@ -1,219 +1,219 @@
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// audio.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 16. audio
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseAudioType(str, input, output) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('speak') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('laut') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('loud') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('head') >= 0) { result = 'Headset'; }
|
||||
if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
if (str.indexOf('mikr') >= 0) { result = 'Microphone'; }
|
||||
if (str.indexOf('phone') >= 0) { result = 'Phone'; }
|
||||
if (str.indexOf('controll') >= 0) { result = 'Controller'; }
|
||||
if (str.indexOf('line o') >= 0) { result = 'Line Out'; }
|
||||
if (str.indexOf('digital o') >= 0) { result = 'Digital Out'; }
|
||||
|
||||
if (!result && output) {
|
||||
result = 'Speaker';
|
||||
} else if (!result && input) {
|
||||
result = 'Microphone';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function getLinuxAudioPci() {
|
||||
let cmd = 'lspci -v 2>/dev/null';
|
||||
let result = [];
|
||||
try {
|
||||
const parts = execSync(cmd).toString().split('\n\n');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const lines = parts[i].split('\n');
|
||||
if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
|
||||
const audio = {};
|
||||
audio.slotId = lines[0].split(' ')[0];
|
||||
audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function parseLinuxAudioPciMM(lines, audioPCI) {
|
||||
const result = {};
|
||||
const slotId = util.getValue(lines, 'Slot');
|
||||
|
||||
const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
|
||||
|
||||
result.id = slotId;
|
||||
result.name = util.getValue(lines, 'SDevice');
|
||||
// result.type = util.getValue(lines, 'Class');
|
||||
result.manufacturer = util.getValue(lines, 'SVendor');
|
||||
result.revision = util.getValue(lines, 'Rev');
|
||||
result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : '';
|
||||
result.default = null;
|
||||
result.channel = 'PCIe';
|
||||
result.type = parseAudioType(result.name, null, null);
|
||||
result.in = null;
|
||||
result.out = null;
|
||||
result.status = 'online';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinChannel(str) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('builtin') >= 0) { result = 'Built-In'; }
|
||||
if (str.indexOf('extern') >= 0) { result = 'Audio-Jack'; }
|
||||
if (str.indexOf('hdmi') >= 0) { result = 'HDMI'; }
|
||||
if (str.indexOf('displayport') >= 0) { result = 'Display-Port'; }
|
||||
if (str.indexOf('usb') >= 0) { result = 'USB'; }
|
||||
if (str.indexOf('pci') >= 0) { result = 'PCIe'; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinAudio(audioObject, id) {
|
||||
const result = {};
|
||||
const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
|
||||
|
||||
result.id = id;
|
||||
result.name = audioObject._name;
|
||||
result.manufacturer = audioObject.coreaudio_device_manufacturer;
|
||||
result.revision = null;
|
||||
result.driver = null;
|
||||
result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
|
||||
result.channel = parseDarwinChannel(channelStr);
|
||||
result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || ''));
|
||||
result.in = !!(audioObject.coreaudio_device_input || '');
|
||||
result.out = !!(audioObject.coreaudio_device_output || '');
|
||||
result.status = 'online';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsAudio(lines) {
|
||||
const result = {};
|
||||
const status = util.getValue(lines, 'StatusInfo', ':');
|
||||
// const description = util.getValue(lines, 'Description', ':');
|
||||
|
||||
result.id = util.getValue(lines, 'DeviceID', ':'); // PNPDeviceID??
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.manufacturer = util.getValue(lines, 'manufacturer', ':');
|
||||
result.revision = null;
|
||||
result.driver = null;
|
||||
result.default = null;
|
||||
result.channel = null;
|
||||
result.type = parseAudioType(result.name, null, null);
|
||||
result.in = null;
|
||||
result.out = null;
|
||||
result.status = status;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function audio(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'lspci -vmm 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
// PCI
|
||||
if (!error) {
|
||||
const audioPCI = getLinuxAudioPci();
|
||||
const parts = stdout.toString().split('\n\n');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const lines = parts[i].split('\n');
|
||||
if (util.getValue(lines, 'class', ':', true).toLowerCase().indexOf('audio') >= 0) {
|
||||
const audio = parseLinuxAudioPciMM(lines, audioPCI);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPAudioDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPAudioDataType && outObj.SPAudioDataType.length && outObj.SPAudioDataType[0] && outObj.SPAudioDataType[0]['_items'] && outObj.SPAudioDataType[0]['_items'].length) {
|
||||
for (let i = 0; i < outObj.SPAudioDataType[0]['_items'].length; i++) {
|
||||
const audio = parseDarwinAudio(outObj.SPAudioDataType[0]['_items'][i], i);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_SoundDevice | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'name', ':')) {
|
||||
result.push(parseWindowsAudio(parts[i].split('\n')));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.audio = audio;
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// audio.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 16. audio
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseAudioType(str, input, output) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('speak') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('laut') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('loud') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('head') >= 0) { result = 'Headset'; }
|
||||
if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
if (str.indexOf('mikr') >= 0) { result = 'Microphone'; }
|
||||
if (str.indexOf('phone') >= 0) { result = 'Phone'; }
|
||||
if (str.indexOf('controll') >= 0) { result = 'Controller'; }
|
||||
if (str.indexOf('line o') >= 0) { result = 'Line Out'; }
|
||||
if (str.indexOf('digital o') >= 0) { result = 'Digital Out'; }
|
||||
|
||||
if (!result && output) {
|
||||
result = 'Speaker';
|
||||
} else if (!result && input) {
|
||||
result = 'Microphone';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function getLinuxAudioPci() {
|
||||
let cmd = 'lspci -v 2>/dev/null';
|
||||
let result = [];
|
||||
try {
|
||||
const parts = execSync(cmd).toString().split('\n\n');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const lines = parts[i].split('\n');
|
||||
if (lines && lines.length && lines[0].toLowerCase().indexOf('audio') >= 0) {
|
||||
const audio = {};
|
||||
audio.slotId = lines[0].split(' ')[0];
|
||||
audio.driver = util.getValue(lines, 'Kernel driver in use', ':', true) || util.getValue(lines, 'Kernel modules', ':', true);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} catch (e) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
function parseLinuxAudioPciMM(lines, audioPCI) {
|
||||
const result = {};
|
||||
const slotId = util.getValue(lines, 'Slot');
|
||||
|
||||
const pciMatch = audioPCI.filter(function (item) { return item.slotId === slotId; });
|
||||
|
||||
result.id = slotId;
|
||||
result.name = util.getValue(lines, 'SDevice');
|
||||
// result.type = util.getValue(lines, 'Class');
|
||||
result.manufacturer = util.getValue(lines, 'SVendor');
|
||||
result.revision = util.getValue(lines, 'Rev');
|
||||
result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : '';
|
||||
result.default = null;
|
||||
result.channel = 'PCIe';
|
||||
result.type = parseAudioType(result.name, null, null);
|
||||
result.in = null;
|
||||
result.out = null;
|
||||
result.status = 'online';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinChannel(str) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('builtin') >= 0) { result = 'Built-In'; }
|
||||
if (str.indexOf('extern') >= 0) { result = 'Audio-Jack'; }
|
||||
if (str.indexOf('hdmi') >= 0) { result = 'HDMI'; }
|
||||
if (str.indexOf('displayport') >= 0) { result = 'Display-Port'; }
|
||||
if (str.indexOf('usb') >= 0) { result = 'USB'; }
|
||||
if (str.indexOf('pci') >= 0) { result = 'PCIe'; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinAudio(audioObject, id) {
|
||||
const result = {};
|
||||
const channelStr = ((audioObject.coreaudio_device_transport || '') + ' ' + (audioObject._name || '')).toLowerCase();
|
||||
|
||||
result.id = id;
|
||||
result.name = audioObject._name;
|
||||
result.manufacturer = audioObject.coreaudio_device_manufacturer;
|
||||
result.revision = null;
|
||||
result.driver = null;
|
||||
result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || '');
|
||||
result.channel = parseDarwinChannel(channelStr);
|
||||
result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || ''));
|
||||
result.in = !!(audioObject.coreaudio_device_input || '');
|
||||
result.out = !!(audioObject.coreaudio_device_output || '');
|
||||
result.status = 'online';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsAudio(lines) {
|
||||
const result = {};
|
||||
const status = util.getValue(lines, 'StatusInfo', ':');
|
||||
// const description = util.getValue(lines, 'Description', ':');
|
||||
|
||||
result.id = util.getValue(lines, 'DeviceID', ':'); // PNPDeviceID??
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.manufacturer = util.getValue(lines, 'manufacturer', ':');
|
||||
result.revision = null;
|
||||
result.driver = null;
|
||||
result.default = null;
|
||||
result.channel = null;
|
||||
result.type = parseAudioType(result.name, null, null);
|
||||
result.in = null;
|
||||
result.out = null;
|
||||
result.status = status;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function audio(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'lspci -vmm 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
// PCI
|
||||
if (!error) {
|
||||
const audioPCI = getLinuxAudioPci();
|
||||
const parts = stdout.toString().split('\n\n');
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const lines = parts[i].split('\n');
|
||||
if (util.getValue(lines, 'class', ':', true).toLowerCase().indexOf('audio') >= 0) {
|
||||
const audio = parseLinuxAudioPciMM(lines, audioPCI);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPAudioDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPAudioDataType && outObj.SPAudioDataType.length && outObj.SPAudioDataType[0] && outObj.SPAudioDataType[0]['_items'] && outObj.SPAudioDataType[0]['_items'].length) {
|
||||
for (let i = 0; i < outObj.SPAudioDataType[0]['_items'].length; i++) {
|
||||
const audio = parseDarwinAudio(outObj.SPAudioDataType[0]['_items'][i], i);
|
||||
result.push(audio);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_SoundDevice | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'name', ':')) {
|
||||
result.push(parseWindowsAudio(parts[i].split('\n')));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.audio = audio;
|
||||
|
||||
618
lib/battery.js
618
lib/battery.js
@ -1,309 +1,309 @@
|
||||
'use strict';
|
||||
// @ts-check;
|
||||
// ==================================================================================
|
||||
// battery.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 6. Battery
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const fs = require('fs');
|
||||
const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
|
||||
const result = {};
|
||||
let status = util.getValue(lines, 'BatteryStatus', ':').trim();
|
||||
// 1 = "Discharging"
|
||||
// 2 = "On A/C"
|
||||
// 3 = "Fully Charged"
|
||||
// 4 = "Low"
|
||||
// 5 = "Critical"
|
||||
// 6 = "Charging"
|
||||
// 7 = "Charging High"
|
||||
// 8 = "Charging Low"
|
||||
// 9 = "Charging Critical"
|
||||
// 10 = "Undefined"
|
||||
// 11 = "Partially Charged"
|
||||
if (status >= 0) {
|
||||
const statusValue = status ? parseInt(status) : 0;
|
||||
result.status = statusValue;
|
||||
result.hasBattery = true;
|
||||
result.maxCapacity = fullChargeCapacity || parseInt(util.getValue(lines, 'DesignCapacity', ':') || 0);
|
||||
result.designedCapacity = parseInt(util.getValue(lines, 'DesignCapacity', ':') || designedCapacity);
|
||||
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.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', ':');
|
||||
} else {
|
||||
result.status = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = function (callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = {
|
||||
hasBattery: false,
|
||||
cycleCount: 0,
|
||||
isCharging: false,
|
||||
designedCapacity: 0,
|
||||
maxCapacity: 0,
|
||||
currentCapacity: 0,
|
||||
voltage: 0,
|
||||
capacityUnit: '',
|
||||
percent: 0,
|
||||
timeRemaining: null,
|
||||
acConnected: true,
|
||||
type: '',
|
||||
model: '',
|
||||
manufacturer: '',
|
||||
serial: ''
|
||||
};
|
||||
|
||||
if (_linux) {
|
||||
let battery_path = '';
|
||||
if (fs.existsSync('/sys/class/power_supply/BAT1/uevent')) {
|
||||
battery_path = '/sys/class/power_supply/BAT1/';
|
||||
} else if (fs.existsSync('/sys/class/power_supply/BAT0/uevent')) {
|
||||
battery_path = '/sys/class/power_supply/BAT0/';
|
||||
}
|
||||
|
||||
let acConnected = false;
|
||||
let acPath = '';
|
||||
if (fs.existsSync('/sys/class/power_supply/AC/online')) {
|
||||
acPath = '/sys/class/power_supply/AC/online';
|
||||
} else if (fs.existsSync('/sys/class/power_supply/AC0/online')) {
|
||||
acPath = '/sys/class/power_supply/AC0/online';
|
||||
}
|
||||
|
||||
if (acPath) {
|
||||
const file = fs.readFileSync(acPath);
|
||||
acConnected = file.toString().trim() === '1';
|
||||
}
|
||||
|
||||
if (battery_path) {
|
||||
fs.readFile(battery_path + 'uevent', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
result.isCharging = (util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging');
|
||||
result.acConnected = acConnected || result.isCharging;
|
||||
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
|
||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||
result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
||||
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0 * (result.voltage || 1));
|
||||
const desingedMinVoltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN', '='), 10) / 1000000.0;
|
||||
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '=', true, true), 10) / 1000.0 * (desingedMinVoltage || result.voltage || 1));
|
||||
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 * (result.voltage || 1));
|
||||
if (!result.maxCapacity) {
|
||||
result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '=', true, true), 10) / 1000.0;
|
||||
result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '=', true, true), 10) / 1000.0 | result.maxCapacity;
|
||||
result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
|
||||
}
|
||||
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
|
||||
const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
|
||||
const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10);
|
||||
const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10);
|
||||
|
||||
result.percent = parseInt('0' + percent, 10);
|
||||
if (result.maxCapacity && result.currentCapacity) {
|
||||
result.hasBattery = true;
|
||||
if (!percent) {
|
||||
result.percent = 100.0 * result.currentCapacity / result.maxCapacity;
|
||||
}
|
||||
}
|
||||
if (result.isCharging) {
|
||||
result.hasBattery = true;
|
||||
}
|
||||
if (energy && power) {
|
||||
result.timeRemaining = Math.floor(energy / power * 60);
|
||||
} else if (current && result.currentCapacity) {
|
||||
result.timeRemaining = Math.floor(result.currentCapacity / current * 60);
|
||||
}
|
||||
result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
|
||||
result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');
|
||||
result.manufacturer = util.getValue(lines, 'POWER_SUPPLY_MANUFACTURER', '=');
|
||||
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
if (_freebsd || _openbsd || _netbsd) {
|
||||
exec('sysctl -i hw.acpi.battery hw.acpi.acline', function (error, stdout) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10);
|
||||
const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10);
|
||||
result.hasBattery = (batteries > 0);
|
||||
result.cycleCount = null;
|
||||
result.isCharging = util.getValue(lines, 'hw.acpi.acline') !== '1';
|
||||
result.acConnected = result.isCharging;
|
||||
result.maxCapacity = null;
|
||||
result.currentCapacity = null;
|
||||
result.capacityUnit = 'unknown';
|
||||
result.percent = batteries ? percent : null;
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining|Voltage"; pmset -g batt | grep %', function (error, stdout) {
|
||||
if (stdout) {
|
||||
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
|
||||
result.cycleCount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
|
||||
result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
|
||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10) * (result.voltage || 1));
|
||||
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10) * (result.voltage || 1));
|
||||
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1));
|
||||
result.manufacturer = 'Apple';
|
||||
result.serial = util.getValue(lines, 'BatterySerialNumber', '=');
|
||||
let percent = null;
|
||||
const line = util.getValue(lines, 'internal', 'Battery');
|
||||
let parts = line.split(';');
|
||||
if (parts && parts[0]) {
|
||||
let parts2 = parts[0].split('\t');
|
||||
if (parts2 && parts2[1]) {
|
||||
percent = parseFloat(parts2[1].trim().replace(/%/g, ''));
|
||||
}
|
||||
}
|
||||
if (parts && parts[1]) {
|
||||
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;
|
||||
result.type = 'Li-ion';
|
||||
result.percent = percent !== null ? percent : Math.round(100.0 * result.currentCapacity / result.maxCapacity);
|
||||
if (!result.isCharging) {
|
||||
result.timeRemaining = parseInt('0' + util.getValue(lines, 'TimeRemaining', '='), 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
const workload = [];
|
||||
workload.push(util.powerShell('Get-WmiObject Win32_Battery | fl *'));
|
||||
workload.push(util.powerShell('(Get-WmiObject -Class BatteryStaticData -Namespace ROOT/WMI).DesignedCapacity'));
|
||||
workload.push(util.powerShell('(Get-WmiObject -Class BatteryFullChargedCapacity -Namespace ROOT/WMI).FullChargedCapacity'));
|
||||
util.promiseAll(
|
||||
workload
|
||||
).then(data => {
|
||||
if (data) {
|
||||
// let parts = data.results[0].split(/\n\s*\n/);
|
||||
let parts = data.results[0].split(/\n\s*\n/);
|
||||
let batteries = [];
|
||||
const hasValue = value => /\S/.test(value);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
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 (batteries.length) {
|
||||
let first = false;
|
||||
let additionalBatteries = [];
|
||||
for (let i = 0; i < batteries.length; i++) {
|
||||
let lines = batteries[i];
|
||||
const designedCapacity = 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, designedCapacity, fullChargeCapacity);
|
||||
if (!first && parsed.status > 0 && parsed.status !== 10) {
|
||||
result.hasBattery = parsed.hasBattery;
|
||||
result.maxCapacity = parsed.maxCapacity;
|
||||
result.designedCapacity = parsed.designedCapacity;
|
||||
result.voltage = parsed.voltage;
|
||||
result.capacityUnit = parsed.capacityUnit;
|
||||
result.percent = parsed.percent;
|
||||
result.currentCapacity = parsed.currentCapacity;
|
||||
result.isCharging = parsed.isCharging;
|
||||
result.acConnected = parsed.acConnected;
|
||||
result.model = parsed.model;
|
||||
first = true;
|
||||
} else if (parsed.status !== -1) {
|
||||
additionalBatteries.push(
|
||||
{
|
||||
hasBattery: parsed.hasBattery,
|
||||
maxCapacity: parsed.maxCapacity,
|
||||
designedCapacity: parsed.designedCapacity,
|
||||
voltage: parsed.voltage,
|
||||
capacityUnit: parsed.capacityUnit,
|
||||
percent: parsed.percent,
|
||||
currentCapacity: parsed.currentCapacity,
|
||||
isCharging: parsed.isCharging,
|
||||
timeRemaining: null,
|
||||
acConnected: parsed.acConnected,
|
||||
model: parsed.model,
|
||||
type: '',
|
||||
manufacturer: '',
|
||||
serial: ''
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!first && additionalBatteries.length) {
|
||||
result = additionalBatteries[0];
|
||||
additionalBatteries.shift();
|
||||
}
|
||||
if (additionalBatteries.length) {
|
||||
result.additionalBatteries = additionalBatteries;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
} catch (e) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
'use strict';
|
||||
// @ts-check;
|
||||
// ==================================================================================
|
||||
// battery.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 6. Battery
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const fs = require('fs');
|
||||
const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseWinBatteryPart(lines, designedCapacity, fullChargeCapacity) {
|
||||
const result = {};
|
||||
let status = util.getValue(lines, 'BatteryStatus', ':').trim();
|
||||
// 1 = "Discharging"
|
||||
// 2 = "On A/C"
|
||||
// 3 = "Fully Charged"
|
||||
// 4 = "Low"
|
||||
// 5 = "Critical"
|
||||
// 6 = "Charging"
|
||||
// 7 = "Charging High"
|
||||
// 8 = "Charging Low"
|
||||
// 9 = "Charging Critical"
|
||||
// 10 = "Undefined"
|
||||
// 11 = "Partially Charged"
|
||||
if (status >= 0) {
|
||||
const statusValue = status ? parseInt(status) : 0;
|
||||
result.status = statusValue;
|
||||
result.hasBattery = true;
|
||||
result.maxCapacity = fullChargeCapacity || parseInt(util.getValue(lines, 'DesignCapacity', ':') || 0);
|
||||
result.designedCapacity = parseInt(util.getValue(lines, 'DesignCapacity', ':') || designedCapacity);
|
||||
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.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', ':');
|
||||
} else {
|
||||
result.status = -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
module.exports = function (callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = {
|
||||
hasBattery: false,
|
||||
cycleCount: 0,
|
||||
isCharging: false,
|
||||
designedCapacity: 0,
|
||||
maxCapacity: 0,
|
||||
currentCapacity: 0,
|
||||
voltage: 0,
|
||||
capacityUnit: '',
|
||||
percent: 0,
|
||||
timeRemaining: null,
|
||||
acConnected: true,
|
||||
type: '',
|
||||
model: '',
|
||||
manufacturer: '',
|
||||
serial: ''
|
||||
};
|
||||
|
||||
if (_linux) {
|
||||
let battery_path = '';
|
||||
if (fs.existsSync('/sys/class/power_supply/BAT1/uevent')) {
|
||||
battery_path = '/sys/class/power_supply/BAT1/';
|
||||
} else if (fs.existsSync('/sys/class/power_supply/BAT0/uevent')) {
|
||||
battery_path = '/sys/class/power_supply/BAT0/';
|
||||
}
|
||||
|
||||
let acConnected = false;
|
||||
let acPath = '';
|
||||
if (fs.existsSync('/sys/class/power_supply/AC/online')) {
|
||||
acPath = '/sys/class/power_supply/AC/online';
|
||||
} else if (fs.existsSync('/sys/class/power_supply/AC0/online')) {
|
||||
acPath = '/sys/class/power_supply/AC0/online';
|
||||
}
|
||||
|
||||
if (acPath) {
|
||||
const file = fs.readFileSync(acPath);
|
||||
acConnected = file.toString().trim() === '1';
|
||||
}
|
||||
|
||||
if (battery_path) {
|
||||
fs.readFile(battery_path + 'uevent', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
result.isCharging = (util.getValue(lines, 'POWER_SUPPLY_STATUS', '=').toLowerCase() === 'charging');
|
||||
result.acConnected = acConnected || result.isCharging;
|
||||
result.voltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_NOW', '='), 10) / 1000000.0;
|
||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||
result.cycleCount = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CYCLE_COUNT', '='), 10);
|
||||
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL', '=', true, true), 10) / 1000.0 * (result.voltage || 1));
|
||||
const desingedMinVoltage = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_VOLTAGE_MIN_DESIGN', '='), 10) / 1000000.0;
|
||||
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_FULL_DESIGN', '=', true, true), 10) / 1000.0 * (desingedMinVoltage || result.voltage || 1));
|
||||
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CHARGE_NOW', '='), 10) / 1000.0 * (result.voltage || 1));
|
||||
if (!result.maxCapacity) {
|
||||
result.maxCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL', '=', true, true), 10) / 1000.0;
|
||||
result.designedCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_FULL_DESIGN', '=', true, true), 10) / 1000.0 | result.maxCapacity;
|
||||
result.currentCapacity = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10) / 1000.0;
|
||||
}
|
||||
const percent = util.getValue(lines, 'POWER_SUPPLY_CAPACITY', '=');
|
||||
const energy = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_ENERGY_NOW', '='), 10);
|
||||
const power = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_POWER_NOW', '='), 10);
|
||||
const current = parseInt('0' + util.getValue(lines, 'POWER_SUPPLY_CURRENT_NOW', '='), 10);
|
||||
|
||||
result.percent = parseInt('0' + percent, 10);
|
||||
if (result.maxCapacity && result.currentCapacity) {
|
||||
result.hasBattery = true;
|
||||
if (!percent) {
|
||||
result.percent = 100.0 * result.currentCapacity / result.maxCapacity;
|
||||
}
|
||||
}
|
||||
if (result.isCharging) {
|
||||
result.hasBattery = true;
|
||||
}
|
||||
if (energy && power) {
|
||||
result.timeRemaining = Math.floor(energy / power * 60);
|
||||
} else if (current && result.currentCapacity) {
|
||||
result.timeRemaining = Math.floor(result.currentCapacity / current * 60);
|
||||
}
|
||||
result.type = util.getValue(lines, 'POWER_SUPPLY_TECHNOLOGY', '=');
|
||||
result.model = util.getValue(lines, 'POWER_SUPPLY_MODEL_NAME', '=');
|
||||
result.manufacturer = util.getValue(lines, 'POWER_SUPPLY_MANUFACTURER', '=');
|
||||
result.serial = util.getValue(lines, 'POWER_SUPPLY_SERIAL_NUMBER', '=');
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
if (_freebsd || _openbsd || _netbsd) {
|
||||
exec('sysctl -i hw.acpi.battery hw.acpi.acline', function (error, stdout) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
const batteries = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.units'), 10);
|
||||
const percent = parseInt('0' + util.getValue(lines, 'hw.acpi.battery.life'), 10);
|
||||
result.hasBattery = (batteries > 0);
|
||||
result.cycleCount = null;
|
||||
result.isCharging = util.getValue(lines, 'hw.acpi.acline') !== '1';
|
||||
result.acConnected = result.isCharging;
|
||||
result.maxCapacity = null;
|
||||
result.currentCapacity = null;
|
||||
result.capacityUnit = 'unknown';
|
||||
result.percent = batteries ? percent : null;
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
|
||||
if (_darwin) {
|
||||
exec('ioreg -n AppleSmartBattery -r | egrep "CycleCount|IsCharging|DesignCapacity|MaxCapacity|CurrentCapacity|BatterySerialNumber|TimeRemaining|Voltage"; pmset -g batt | grep %', function (error, stdout) {
|
||||
if (stdout) {
|
||||
let lines = stdout.toString().replace(/ +/g, '').replace(/"+/g, '').replace(/-/g, '').split('\n');
|
||||
result.cycleCount = parseInt('0' + util.getValue(lines, 'cyclecount', '='), 10);
|
||||
result.voltage = parseInt('0' + util.getValue(lines, 'voltage', '='), 10) / 1000.0;
|
||||
result.capacityUnit = result.voltage ? 'mWh' : 'mAh';
|
||||
result.maxCapacity = Math.round(parseInt('0' + util.getValue(lines, 'maxcapacity', '='), 10) * (result.voltage || 1));
|
||||
result.currentCapacity = Math.round(parseInt('0' + util.getValue(lines, 'currentcapacity', '='), 10) * (result.voltage || 1));
|
||||
result.designedCapacity = Math.round(parseInt('0' + util.getValue(lines, 'DesignCapacity', '='), 10) * (result.voltage || 1));
|
||||
result.manufacturer = 'Apple';
|
||||
result.serial = util.getValue(lines, 'BatterySerialNumber', '=');
|
||||
let percent = null;
|
||||
const line = util.getValue(lines, 'internal', 'Battery');
|
||||
let parts = line.split(';');
|
||||
if (parts && parts[0]) {
|
||||
let parts2 = parts[0].split('\t');
|
||||
if (parts2 && parts2[1]) {
|
||||
percent = parseFloat(parts2[1].trim().replace(/%/g, ''));
|
||||
}
|
||||
}
|
||||
if (parts && parts[1]) {
|
||||
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;
|
||||
result.type = 'Li-ion';
|
||||
result.percent = percent !== null ? percent : Math.round(100.0 * result.currentCapacity / result.maxCapacity);
|
||||
if (!result.isCharging) {
|
||||
result.timeRemaining = parseInt('0' + util.getValue(lines, 'TimeRemaining', '='), 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
if (_windows) {
|
||||
try {
|
||||
const workload = [];
|
||||
workload.push(util.powerShell('Get-WmiObject Win32_Battery | fl *'));
|
||||
workload.push(util.powerShell('(Get-WmiObject -Class BatteryStaticData -Namespace ROOT/WMI).DesignedCapacity'));
|
||||
workload.push(util.powerShell('(Get-WmiObject -Class BatteryFullChargedCapacity -Namespace ROOT/WMI).FullChargedCapacity'));
|
||||
util.promiseAll(
|
||||
workload
|
||||
).then(data => {
|
||||
if (data) {
|
||||
// let parts = data.results[0].split(/\n\s*\n/);
|
||||
let parts = data.results[0].split(/\n\s*\n/);
|
||||
let batteries = [];
|
||||
const hasValue = value => /\S/.test(value);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
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 (batteries.length) {
|
||||
let first = false;
|
||||
let additionalBatteries = [];
|
||||
for (let i = 0; i < batteries.length; i++) {
|
||||
let lines = batteries[i];
|
||||
const designedCapacity = 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, designedCapacity, fullChargeCapacity);
|
||||
if (!first && parsed.status > 0 && parsed.status !== 10) {
|
||||
result.hasBattery = parsed.hasBattery;
|
||||
result.maxCapacity = parsed.maxCapacity;
|
||||
result.designedCapacity = parsed.designedCapacity;
|
||||
result.voltage = parsed.voltage;
|
||||
result.capacityUnit = parsed.capacityUnit;
|
||||
result.percent = parsed.percent;
|
||||
result.currentCapacity = parsed.currentCapacity;
|
||||
result.isCharging = parsed.isCharging;
|
||||
result.acConnected = parsed.acConnected;
|
||||
result.model = parsed.model;
|
||||
first = true;
|
||||
} else if (parsed.status !== -1) {
|
||||
additionalBatteries.push(
|
||||
{
|
||||
hasBattery: parsed.hasBattery,
|
||||
maxCapacity: parsed.maxCapacity,
|
||||
designedCapacity: parsed.designedCapacity,
|
||||
voltage: parsed.voltage,
|
||||
capacityUnit: parsed.capacityUnit,
|
||||
percent: parsed.percent,
|
||||
currentCapacity: parsed.currentCapacity,
|
||||
isCharging: parsed.isCharging,
|
||||
timeRemaining: null,
|
||||
acConnected: parsed.acConnected,
|
||||
model: parsed.model,
|
||||
type: '',
|
||||
manufacturer: '',
|
||||
serial: ''
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
if (!first && additionalBatteries.length) {
|
||||
result = additionalBatteries[0];
|
||||
additionalBatteries.shift();
|
||||
}
|
||||
if (additionalBatteries.length) {
|
||||
result.additionalBatteries = additionalBatteries;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
});
|
||||
} catch (e) {
|
||||
if (callback) { callback(result); }
|
||||
resolve(result);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
366
lib/bluetooth.js
366
lib/bluetooth.js
@ -1,183 +1,183 @@
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// audio.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 17. bluetooth
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const path = require('path');
|
||||
const util = require('./util');
|
||||
const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseBluetoothType(str) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
if (str.indexOf('speaker') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('headset') >= 0) { result = 'Headset'; }
|
||||
if (str.indexOf('phone') >= 0) { result = 'Phone'; }
|
||||
// to be continued ...
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxBluetoothInfo(lines, macAddr1, macAddr2) {
|
||||
const result = {};
|
||||
|
||||
result.device = null;
|
||||
result.name = util.getValue(lines, 'name', '=');
|
||||
result.manufacturer = null;
|
||||
result.macDevice = macAddr1;
|
||||
result.macHost = macAddr2;
|
||||
result.batteryPercent = null;
|
||||
result.type = parseBluetoothType(result.name.toLowerCase());
|
||||
result.connected = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {
|
||||
const result = {};
|
||||
const typeStr = ((bluetoothObject.device_minorClassOfDevice_string || bluetoothObject.device_majorClassOfDevice_string || '') + (bluetoothObject.device_name || '')).toLowerCase();
|
||||
|
||||
result.device = bluetoothObject.device_services || '';
|
||||
result.name = bluetoothObject.device_name || '';
|
||||
result.manufacturer = bluetoothObject.device_manufacturer || '';
|
||||
result.macDevice = (bluetoothObject.device_addr || '').toLowerCase().replace(/-/g, ':');
|
||||
result.macHost = macAddr2;
|
||||
result.batteryPercent = bluetoothObject.device_batteryPercent || null;
|
||||
result.type = parseBluetoothType(typeStr);
|
||||
result.connected = bluetoothObject.device_isconnected === 'attrib_Yes' || false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsBluetooth(lines) {
|
||||
const result = {};
|
||||
|
||||
result.device = null;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.manufacturer = util.getValue(lines, 'manufacturer', ':');
|
||||
result.macDevice = null;
|
||||
result.macHost = null;
|
||||
result.batteryPercent = null;
|
||||
result.type = parseBluetoothType(result.name.toLowerCase());
|
||||
result.connected = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function bluetoothDevices(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux) {
|
||||
// get files in /var/lib/bluetooth/ recursive
|
||||
const btFiles = util.getFilesInPath('/var/lib/bluetooth/');
|
||||
for (let i = 0; i < btFiles.length; i++) {
|
||||
const filename = path.basename(btFiles[i]);
|
||||
const pathParts = btFiles[i].split('/');
|
||||
const macAddr1 = pathParts.length >= 6 ? pathParts[pathParts.length - 2] : null;
|
||||
const macAddr2 = pathParts.length >= 7 ? pathParts[pathParts.length - 3] : null;
|
||||
if (filename === 'info') {
|
||||
const infoFile = fs.readFileSync(btFiles[i], { encoding: 'utf8' }).split('\n');
|
||||
result.push(parseLinuxBluetoothInfo(infoFile, macAddr1, macAddr2));
|
||||
}
|
||||
}
|
||||
// determine "connected" with hcitool con
|
||||
try {
|
||||
const hdicon = execSync('hcitool con').toString().toLowerCase();
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i].macDevice && result[i].macDevice.length > 10 && hdicon.indexOf(result[i].macDevice.toLowerCase()) >= 0) {
|
||||
result[i].connected = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPBluetoothDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPBluetoothDataType && outObj.SPBluetoothDataType.length && outObj.SPBluetoothDataType[0] && outObj.SPBluetoothDataType[0]['device_title'] && outObj.SPBluetoothDataType[0]['device_title'].length) {
|
||||
// missing: host BT Adapter macAddr ()
|
||||
let macAddr2 = null;
|
||||
if (outObj.SPBluetoothDataType[0]['local_device_title'] && outObj.SPBluetoothDataType[0].local_device_title.general_address) {
|
||||
macAddr2 = outObj.SPBluetoothDataType[0].local_device_title.general_address.toLowerCase().replace(/-/g, ':');
|
||||
}
|
||||
|
||||
for (let i = 0; i < outObj.SPBluetoothDataType[0]['device_title'].length; i++) {
|
||||
const obj = outObj.SPBluetoothDataType[0]['device_title'][i];
|
||||
const objKey = Object.keys(obj);
|
||||
if (objKey && objKey.length === 1) {
|
||||
const innerObject = obj[objKey[0]];
|
||||
innerObject.device_name = objKey[0];
|
||||
const bluetoothDevice = parseDarwinBluetoothDevices(innerObject, macAddr2);
|
||||
result.push(bluetoothDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_PNPEntity | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'PNPClass', ':') === 'Bluetooth') {
|
||||
result.push(parseWindowsBluetooth(parts[i].split('\n')));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_freebsd || _netbsd || _openbsd || _sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.bluetoothDevices = bluetoothDevices;
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// audio.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 17. bluetooth
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
const execSync = require('child_process').execSync;
|
||||
const path = require('path');
|
||||
const util = require('./util');
|
||||
const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function parseBluetoothType(str) {
|
||||
let result = '';
|
||||
|
||||
if (str.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
if (str.indexOf('speaker') >= 0) { result = 'Speaker'; }
|
||||
if (str.indexOf('headset') >= 0) { result = 'Headset'; }
|
||||
if (str.indexOf('phone') >= 0) { result = 'Phone'; }
|
||||
// to be continued ...
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxBluetoothInfo(lines, macAddr1, macAddr2) {
|
||||
const result = {};
|
||||
|
||||
result.device = null;
|
||||
result.name = util.getValue(lines, 'name', '=');
|
||||
result.manufacturer = null;
|
||||
result.macDevice = macAddr1;
|
||||
result.macHost = macAddr2;
|
||||
result.batteryPercent = null;
|
||||
result.type = parseBluetoothType(result.name.toLowerCase());
|
||||
result.connected = false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinBluetoothDevices(bluetoothObject, macAddr2) {
|
||||
const result = {};
|
||||
const typeStr = ((bluetoothObject.device_minorClassOfDevice_string || bluetoothObject.device_majorClassOfDevice_string || '') + (bluetoothObject.device_name || '')).toLowerCase();
|
||||
|
||||
result.device = bluetoothObject.device_services || '';
|
||||
result.name = bluetoothObject.device_name || '';
|
||||
result.manufacturer = bluetoothObject.device_manufacturer || '';
|
||||
result.macDevice = (bluetoothObject.device_addr || '').toLowerCase().replace(/-/g, ':');
|
||||
result.macHost = macAddr2;
|
||||
result.batteryPercent = bluetoothObject.device_batteryPercent || null;
|
||||
result.type = parseBluetoothType(typeStr);
|
||||
result.connected = bluetoothObject.device_isconnected === 'attrib_Yes' || false;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsBluetooth(lines) {
|
||||
const result = {};
|
||||
|
||||
result.device = null;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.manufacturer = util.getValue(lines, 'manufacturer', ':');
|
||||
result.macDevice = null;
|
||||
result.macHost = null;
|
||||
result.batteryPercent = null;
|
||||
result.type = parseBluetoothType(result.name.toLowerCase());
|
||||
result.connected = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function bluetoothDevices(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux) {
|
||||
// get files in /var/lib/bluetooth/ recursive
|
||||
const btFiles = util.getFilesInPath('/var/lib/bluetooth/');
|
||||
for (let i = 0; i < btFiles.length; i++) {
|
||||
const filename = path.basename(btFiles[i]);
|
||||
const pathParts = btFiles[i].split('/');
|
||||
const macAddr1 = pathParts.length >= 6 ? pathParts[pathParts.length - 2] : null;
|
||||
const macAddr2 = pathParts.length >= 7 ? pathParts[pathParts.length - 3] : null;
|
||||
if (filename === 'info') {
|
||||
const infoFile = fs.readFileSync(btFiles[i], { encoding: 'utf8' }).split('\n');
|
||||
result.push(parseLinuxBluetoothInfo(infoFile, macAddr1, macAddr2));
|
||||
}
|
||||
}
|
||||
// determine "connected" with hcitool con
|
||||
try {
|
||||
const hdicon = execSync('hcitool con').toString().toLowerCase();
|
||||
for (let i = 0; i < result.length; i++) {
|
||||
if (result[i].macDevice && result[i].macDevice.length > 10 && hdicon.indexOf(result[i].macDevice.toLowerCase()) >= 0) {
|
||||
result[i].connected = true;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPBluetoothDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPBluetoothDataType && outObj.SPBluetoothDataType.length && outObj.SPBluetoothDataType[0] && outObj.SPBluetoothDataType[0]['device_title'] && outObj.SPBluetoothDataType[0]['device_title'].length) {
|
||||
// missing: host BT Adapter macAddr ()
|
||||
let macAddr2 = null;
|
||||
if (outObj.SPBluetoothDataType[0]['local_device_title'] && outObj.SPBluetoothDataType[0].local_device_title.general_address) {
|
||||
macAddr2 = outObj.SPBluetoothDataType[0].local_device_title.general_address.toLowerCase().replace(/-/g, ':');
|
||||
}
|
||||
|
||||
for (let i = 0; i < outObj.SPBluetoothDataType[0]['device_title'].length; i++) {
|
||||
const obj = outObj.SPBluetoothDataType[0]['device_title'][i];
|
||||
const objKey = Object.keys(obj);
|
||||
if (objKey && objKey.length === 1) {
|
||||
const innerObject = obj[objKey[0]];
|
||||
innerObject.device_name = objKey[0];
|
||||
const bluetoothDevice = parseDarwinBluetoothDevices(innerObject, macAddr2);
|
||||
result.push(bluetoothDevice);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_PNPEntity | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
if (util.getValue(parts[i].split('\n'), 'PNPClass', ':') === 'Bluetooth') {
|
||||
result.push(parseWindowsBluetooth(parts[i].split('\n')));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_freebsd || _netbsd || _openbsd || _sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.bluetoothDevices = bluetoothDevices;
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -21,7 +21,7 @@ const si = require('./index');
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Main
|
||||
// ----------------------------------------------------------------------------------
|
||||
(function() {
|
||||
(function () {
|
||||
si.getStaticData().then(
|
||||
(data => {
|
||||
data.time = si.time();
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -21,7 +21,7 @@ const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -22,7 +22,7 @@ const execPromiseSave = util.promisifySave(require('child_process').exec);
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -21,7 +21,7 @@ const util = require('./util');
|
||||
let _platform = process.platform;
|
||||
let _nvidiaSmiPath = '';
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
1026
lib/index.js
1026
lib/index.js
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -18,7 +18,7 @@ const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -21,7 +21,7 @@ const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
@ -226,11 +226,18 @@ function mem(callback) {
|
||||
resolve(result);
|
||||
}
|
||||
if (_darwin) {
|
||||
let pageSize = 4096;
|
||||
try {
|
||||
let sysPpageSize = util.toInt(execSync('sysctl -n vm.pagesize').toString());
|
||||
pageSize = sysPpageSize || pageSize;
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
exec('vm_stat 2>/dev/null | grep "Pages active"', function (error, stdout) {
|
||||
if (!error) {
|
||||
let lines = stdout.toString().split('\n');
|
||||
|
||||
result.active = parseInt(lines[0].split(':')[1], 10) * 4096;
|
||||
result.active = parseInt(lines[0].split(':')[1], 10) * pageSize;
|
||||
result.buffcache = result.used - result.active;
|
||||
result.available = result.free + result.buffcache;
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -21,7 +21,7 @@ const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -22,7 +22,7 @@ const execSync = require('child_process').execSync;
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
424
lib/printer.js
424
lib/printer.js
@ -1,212 +1,212 @@
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// printers.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 15. printers
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
// const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
const winPrinterStatus = {
|
||||
1: 'Other',
|
||||
2: 'Unknown',
|
||||
3: 'Idle',
|
||||
4: 'Printing',
|
||||
5: 'Warmup',
|
||||
6: 'Stopped Printing',
|
||||
7: 'Offline',
|
||||
};
|
||||
|
||||
function parseLinuxCupsHeader(lines) {
|
||||
const result = {};
|
||||
if (lines && lines.length) {
|
||||
if (lines[0].indexOf(' CUPS v') > 0) {
|
||||
const parts = lines[0].split(' CUPS v');
|
||||
result.cupsVersion = parts[1];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxCupsPrinter(lines) {
|
||||
const result = {};
|
||||
const printerId = util.getValue(lines, 'PrinterId', ' ');
|
||||
result.id = printerId ? parseInt(printerId, 10) : null;
|
||||
result.name = util.getValue(lines, 'Info', ' ');
|
||||
result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
|
||||
result.uri = util.getValue(lines, 'DeviceURI', ' ');
|
||||
result.uuid = util.getValue(lines, 'UUID', ' ');
|
||||
result.status = util.getValue(lines, 'State', ' ');
|
||||
result.local = util.getValue(lines, 'Location', ' ').toLowerCase().startsWith('local');
|
||||
result.default = null;
|
||||
result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxLpstatPrinter(lines, id) {
|
||||
const result = {};
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'Description', ':', true);
|
||||
result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
|
||||
result.uri = null;
|
||||
result.uuid = null;
|
||||
result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null;
|
||||
result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local');
|
||||
result.default = null;
|
||||
result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinPrinters(printerObject, id) {
|
||||
const result = {};
|
||||
const uriParts = printerObject.uri.split('/');
|
||||
result.id = id;
|
||||
result.name = printerObject._name;
|
||||
result.model = uriParts.length ? uriParts[uriParts.length - 1] : '';
|
||||
result.uri = printerObject.uri;
|
||||
result.uuid = null;
|
||||
result.status = printerObject.status;
|
||||
result.local = printerObject.printserver === 'local';
|
||||
result.default = printerObject.default === 'yes';
|
||||
result.shared = printerObject.shared === 'yes';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsPrinters(lines, id) {
|
||||
const result = {};
|
||||
const status = parseInt(util.getValue(lines, 'PrinterStatus', ':'), 10);
|
||||
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.model = util.getValue(lines, 'DriverName', ':');
|
||||
result.uri = null;
|
||||
result.uuid = null;
|
||||
result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null;
|
||||
result.local = util.getValue(lines, 'Local', ':').toUpperCase() === 'TRUE';
|
||||
result.default = util.getValue(lines, 'Default', ':').toUpperCase() === 'TRUE';
|
||||
result.shared = util.getValue(lines, 'Shared', ':').toUpperCase() === 'TRUE';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function printer(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'cat /etc/cups/printers.conf 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
// printers.conf
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split('<Printer ');
|
||||
const printerHeader = parseLinuxCupsHeader(parts[0]);
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
|
||||
if (printers.name) {
|
||||
printers.engine = 'CUPS';
|
||||
printers.engineVersion = printerHeader.cupsVersion;
|
||||
result.push(printers);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.length === 0) {
|
||||
if (_linux) {
|
||||
cmd = 'export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL';
|
||||
// lpstat
|
||||
exec(cmd, function (error, stdout) {
|
||||
const parts = ('\n' + stdout.toString()).split('\nprinter ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
|
||||
result.push(printers);
|
||||
}
|
||||
});
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPPrintersDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPPrintersDataType && outObj.SPPrintersDataType.length) {
|
||||
for (let i = 0; i < outObj.SPPrintersDataType.length; i++) {
|
||||
const printer = parseDarwinPrinters(outObj.SPPrintersDataType[i], i);
|
||||
result.push(printer);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_Printer | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const printer = parseWindowsPrinters(parts[i].split('\n'), i);
|
||||
if (printer.name || printer.model) {
|
||||
result.push(parseWindowsPrinters(parts[i].split('\n'), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.printer = printer;
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// printers.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 15. printers
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
// const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
const winPrinterStatus = {
|
||||
1: 'Other',
|
||||
2: 'Unknown',
|
||||
3: 'Idle',
|
||||
4: 'Printing',
|
||||
5: 'Warmup',
|
||||
6: 'Stopped Printing',
|
||||
7: 'Offline',
|
||||
};
|
||||
|
||||
function parseLinuxCupsHeader(lines) {
|
||||
const result = {};
|
||||
if (lines && lines.length) {
|
||||
if (lines[0].indexOf(' CUPS v') > 0) {
|
||||
const parts = lines[0].split(' CUPS v');
|
||||
result.cupsVersion = parts[1];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxCupsPrinter(lines) {
|
||||
const result = {};
|
||||
const printerId = util.getValue(lines, 'PrinterId', ' ');
|
||||
result.id = printerId ? parseInt(printerId, 10) : null;
|
||||
result.name = util.getValue(lines, 'Info', ' ');
|
||||
result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
|
||||
result.uri = util.getValue(lines, 'DeviceURI', ' ');
|
||||
result.uuid = util.getValue(lines, 'UUID', ' ');
|
||||
result.status = util.getValue(lines, 'State', ' ');
|
||||
result.local = util.getValue(lines, 'Location', ' ').toLowerCase().startsWith('local');
|
||||
result.default = null;
|
||||
result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxLpstatPrinter(lines, id) {
|
||||
const result = {};
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'Description', ':', true);
|
||||
result.model = lines.length > 0 && lines[0] ? lines[0].split(' ')[0] : '';
|
||||
result.uri = null;
|
||||
result.uuid = null;
|
||||
result.status = lines.length > 0 && lines[0] ? (lines[0].indexOf(' idle') > 0 ? 'idle' : (lines[0].indexOf(' printing') > 0 ? 'printing' : 'unknown')) : null;
|
||||
result.local = util.getValue(lines, 'Location', ':', true).toLowerCase().startsWith('local');
|
||||
result.default = null;
|
||||
result.shared = util.getValue(lines, 'Shared', ' ').toLowerCase().startsWith('yes');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseDarwinPrinters(printerObject, id) {
|
||||
const result = {};
|
||||
const uriParts = printerObject.uri.split('/');
|
||||
result.id = id;
|
||||
result.name = printerObject._name;
|
||||
result.model = uriParts.length ? uriParts[uriParts.length - 1] : '';
|
||||
result.uri = printerObject.uri;
|
||||
result.uuid = null;
|
||||
result.status = printerObject.status;
|
||||
result.local = printerObject.printserver === 'local';
|
||||
result.default = printerObject.default === 'yes';
|
||||
result.shared = printerObject.shared === 'yes';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsPrinters(lines, id) {
|
||||
const result = {};
|
||||
const status = parseInt(util.getValue(lines, 'PrinterStatus', ':'), 10);
|
||||
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.model = util.getValue(lines, 'DriverName', ':');
|
||||
result.uri = null;
|
||||
result.uuid = null;
|
||||
result.status = winPrinterStatus[status] ? winPrinterStatus[status] : null;
|
||||
result.local = util.getValue(lines, 'Local', ':').toUpperCase() === 'TRUE';
|
||||
result.default = util.getValue(lines, 'Default', ':').toUpperCase() === 'TRUE';
|
||||
result.shared = util.getValue(lines, 'Shared', ':').toUpperCase() === 'TRUE';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function printer(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux || _freebsd || _openbsd || _netbsd) {
|
||||
let cmd = 'cat /etc/cups/printers.conf 2>/dev/null';
|
||||
exec(cmd, function (error, stdout) {
|
||||
// printers.conf
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split('<Printer ');
|
||||
const printerHeader = parseLinuxCupsHeader(parts[0]);
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const printers = parseLinuxCupsPrinter(parts[i].split('\n'));
|
||||
if (printers.name) {
|
||||
printers.engine = 'CUPS';
|
||||
printers.engineVersion = printerHeader.cupsVersion;
|
||||
result.push(printers);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.length === 0) {
|
||||
if (_linux) {
|
||||
cmd = 'export LC_ALL=C; lpstat -lp 2>/dev/null; unset LC_ALL';
|
||||
// lpstat
|
||||
exec(cmd, function (error, stdout) {
|
||||
const parts = ('\n' + stdout.toString()).split('\nprinter ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const printers = parseLinuxLpstatPrinter(parts[i].split('\n'), i);
|
||||
result.push(printers);
|
||||
}
|
||||
});
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
} else {
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'system_profiler SPPrintersDataType -json';
|
||||
exec(cmd, function (error, stdout) {
|
||||
if (!error) {
|
||||
try {
|
||||
const outObj = JSON.parse(stdout.toString());
|
||||
if (outObj.SPPrintersDataType && outObj.SPPrintersDataType.length) {
|
||||
for (let i = 0; i < outObj.SPPrintersDataType.length; i++) {
|
||||
const printer = parseDarwinPrinters(outObj.SPPrintersDataType[i], i);
|
||||
result.push(printer);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
util.noop();
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject Win32_Printer | fl *').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const printer = parseWindowsPrinters(parts[i].split('\n'), i);
|
||||
if (printer.name || printer.model) {
|
||||
result.push(parseWindowsPrinters(parts[i].split('\n'), i));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_sunos) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.printer = printer;
|
||||
|
||||
2480
lib/processes.js
2480
lib/processes.js
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -22,7 +22,7 @@ const execPromise = util.promisify(require('child_process').exec);
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
610
lib/usb.js
610
lib/usb.js
@ -1,305 +1,305 @@
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// usb.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 16. usb
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
// const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function getLinuxUsbType(type, name) {
|
||||
let result = type;
|
||||
const str = (name + ' ' + type).toLowerCase();
|
||||
if (str.indexOf('camera') >= 0) { result = 'Camera'; }
|
||||
else if (str.indexOf('hub') >= 0) { result = 'Hub'; }
|
||||
else if (str.indexOf('keybrd') >= 0) { result = 'Keyboard'; }
|
||||
else if (str.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
else if (str.indexOf('stora') >= 0) { result = 'Storage'; }
|
||||
else if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
else if (str.indexOf('headset') >= 0) { result = 'Audio'; }
|
||||
else if (str.indexOf('audio') >= 0) { result = 'Audio'; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxUsb(usb) {
|
||||
const result = {};
|
||||
const lines = usb.split('\n');
|
||||
if (lines && lines.length && lines[0].indexOf('Device') >= 0) {
|
||||
const parts = lines[0].split(' ');
|
||||
result.bus = parseInt(parts[0], 10);
|
||||
if (parts[2]) {
|
||||
result.deviceId = parseInt(parts[2], 10);
|
||||
} else {
|
||||
result.deviceId = null;
|
||||
}
|
||||
} else {
|
||||
result.bus = null;
|
||||
result.deviceId = null;
|
||||
}
|
||||
const idVendor = util.getValue(lines, 'idVendor', ' ', true).trim();
|
||||
let vendorParts = idVendor.split(' ');
|
||||
vendorParts.shift();
|
||||
const vendor = vendorParts.join(' ');
|
||||
|
||||
const idProduct = util.getValue(lines, 'idProduct', ' ', true).trim();
|
||||
let productParts = idProduct.split(' ');
|
||||
productParts.shift();
|
||||
const product = productParts.join(' ');
|
||||
|
||||
const interfaceClass = util.getValue(lines, 'bInterfaceClass', ' ', true).trim();
|
||||
let interfaceClassParts = interfaceClass.split(' ');
|
||||
interfaceClassParts.shift();
|
||||
const usbType = interfaceClassParts.join(' ');
|
||||
|
||||
const iManufacturer = util.getValue(lines, 'iManufacturer', ' ', true).trim();
|
||||
let iManufacturerParts = iManufacturer.split(' ');
|
||||
iManufacturerParts.shift();
|
||||
const manufacturer = iManufacturerParts.join(' ');
|
||||
|
||||
result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : '');
|
||||
result.name = product;
|
||||
result.type = getLinuxUsbType(usbType, product);
|
||||
result.removable = null;
|
||||
result.vendor = vendor;
|
||||
result.manufacturer = manufacturer;
|
||||
result.maxPower = util.getValue(lines, 'MaxPower', ' ', true);
|
||||
result.serialNumber = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// bus
|
||||
// deviceId
|
||||
// id
|
||||
// name(product)
|
||||
// type(bInterfaceClass)
|
||||
// removable / hotplug
|
||||
// vendor
|
||||
// manufacturer
|
||||
// maxpower(linux)
|
||||
|
||||
function getDarwinUsbType(name) {
|
||||
let result = '';
|
||||
if (name.indexOf('camera') >= 0) { result = 'Camera'; }
|
||||
else if (name.indexOf('touch bar') >= 0) { result = 'Touch Bar'; }
|
||||
else if (name.indexOf('controller') >= 0) { result = 'Controller'; }
|
||||
else if (name.indexOf('headset') >= 0) { result = 'Audio'; }
|
||||
else if (name.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (name.indexOf('trackpad') >= 0) { result = 'Trackpad'; }
|
||||
else if (name.indexOf('sensor') >= 0) { result = 'Sensor'; }
|
||||
else if (name.indexOf('bthusb') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('bth') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('rfcomm') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
else if (name.indexOf(' hub') >= 0) { result = 'Hub'; }
|
||||
else if (name.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
else if (name.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
else if (name.indexOf('removable') >= 0) { result = 'Storage'; }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function parseDarwinUsb(usb, id) {
|
||||
const result = {};
|
||||
result.id = id;
|
||||
|
||||
usb = usb.replace(/ \|/g, '');
|
||||
usb = usb.trim();
|
||||
let lines = usb.split('\n');
|
||||
lines.shift();
|
||||
try {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
lines[i] = lines[i].trim();
|
||||
lines[i] = lines[i].replace(/=/g, ':');
|
||||
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
|
||||
lines[i] = lines[i] + ',';
|
||||
}
|
||||
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
|
||||
lines[i] = lines[i].replace(': No,', ': "No",');
|
||||
}
|
||||
const usbObj = JSON.parse(lines.join('\n'));
|
||||
const removableDrive = usbObj['Built-In'].toLowerCase() !== 'yes' && usbObj['non-removable'].toLowerCase() === 'no';
|
||||
|
||||
result.bus = null;
|
||||
result.deviceId = null;
|
||||
result.id = usbObj['USB Address'] || null;
|
||||
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
|
||||
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase() + (removableDrive ? ' removable' : ''));
|
||||
result.removable = usbObj['non-removable'].toLowerCase() === 'no';
|
||||
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
result.maxPower = null;
|
||||
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
|
||||
|
||||
if (result.name) {
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// function getWindowsUsbType(service) {
|
||||
// let result = ''
|
||||
// if (service.indexOf('usbhub3') >= 0) { result = 'Hub'; }
|
||||
// else if (service.indexOf('usbstor') >= 0) { result = 'Storage'; }
|
||||
// else if (service.indexOf('hidusb') >= 0) { result = 'Input'; }
|
||||
// else if (service.indexOf('usbccgp') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('usbxhci') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('usbehci') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('kbdhid') >= 0) { result = 'Keyboard'; }
|
||||
// else if (service.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
// else if (service.indexOf('pointing') >= 0) { result = 'Mouse'; }
|
||||
// else if (service.indexOf('disk') >= 0) { result = 'Storage'; }
|
||||
// else if (service.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
// else if (service.indexOf('bthusb') >= 0) { result = ''; }
|
||||
// else if (service.indexOf('bth') >= 0) { result = ''; }
|
||||
// else if (service.indexOf('rfcomm') >= 0) { result = ''; }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
function getWindowsUsbTypeCreation(creationclass, name) {
|
||||
let result = '';
|
||||
if (name.indexOf('storage') >= 0) { result = 'Storage'; }
|
||||
else if (name.indexOf('speicher') >= 0) { result = 'Storage'; }
|
||||
else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
else if (creationclass.indexOf('storage') >= 0) { result = 'Storage'; }
|
||||
else if (creationclass.indexOf('usbcontroller') >= 0) { result = 'Controller'; }
|
||||
else if (creationclass.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (creationclass.indexOf('pointing') >= 0) { result = 'Mouse'; }
|
||||
else if (creationclass.indexOf('disk') >= 0) { result = 'Storage'; }
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsUsb(lines, id) {
|
||||
const usbType = getWindowsUsbTypeCreation(util.getValue(lines, 'CreationClassName', ':').toLowerCase(), util.getValue(lines, 'name', ':').toLowerCase());
|
||||
|
||||
if (usbType) {
|
||||
const result = {};
|
||||
result.bus = null;
|
||||
result.deviceId = util.getValue(lines, 'deviceid', ':');
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.type = usbType;
|
||||
result.removable = null;
|
||||
result.vendor = null;
|
||||
result.manufacturer = util.getValue(lines, 'Manufacturer', ':');
|
||||
result.maxPower = null;
|
||||
result.serialNumber = null;
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function usb(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux) {
|
||||
const cmd = 'export LC_ALL=C; lsusb -v 2>/dev/null; unset LC_ALL';
|
||||
exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
const parts = ('\n\n' + stdout.toString()).split('\n\nBus ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const usb = parseLinuxUsb(parts[i]);
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l';
|
||||
exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
const parts = (stdout.toString()).split(' +-o ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const usb = parseDarwinUsb(parts[i]);
|
||||
if (usb) {
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "^USB"}').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const usb = parseWindowsUsb(parts[i].split('\n'), i);
|
||||
if (usb) {
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
// util.powerShell("gwmi Win32_USBControllerDevice |\%{[wmi]($_.Dependent)}").then(data => {
|
||||
|
||||
// const parts = data.toString().split(/\n\s*\n/);
|
||||
// for (let i = 0; i < parts.length; i++) {
|
||||
// const usb = parseWindowsUsb(parts[i].split('\n'), i)
|
||||
// if (usb) {
|
||||
// result.push(usb)
|
||||
// }
|
||||
// }
|
||||
// if (callback) {
|
||||
// callback(result);
|
||||
// }
|
||||
// resolve(result);
|
||||
// });
|
||||
}
|
||||
if (_sunos || _freebsd || _openbsd || _netbsd) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.usb = usb;
|
||||
|
||||
'use strict';
|
||||
// @ts-check
|
||||
// ==================================================================================
|
||||
// usb.js
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
// ==================================================================================
|
||||
// 16. usb
|
||||
// ----------------------------------------------------------------------------------
|
||||
|
||||
const exec = require('child_process').exec;
|
||||
// const execSync = require('child_process').execSync;
|
||||
const util = require('./util');
|
||||
// const fs = require('fs');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
const _openbsd = (_platform === 'openbsd');
|
||||
const _netbsd = (_platform === 'netbsd');
|
||||
const _sunos = (_platform === 'sunos');
|
||||
|
||||
function getLinuxUsbType(type, name) {
|
||||
let result = type;
|
||||
const str = (name + ' ' + type).toLowerCase();
|
||||
if (str.indexOf('camera') >= 0) { result = 'Camera'; }
|
||||
else if (str.indexOf('hub') >= 0) { result = 'Hub'; }
|
||||
else if (str.indexOf('keybrd') >= 0) { result = 'Keyboard'; }
|
||||
else if (str.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (str.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
else if (str.indexOf('stora') >= 0) { result = 'Storage'; }
|
||||
else if (str.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
else if (str.indexOf('headset') >= 0) { result = 'Audio'; }
|
||||
else if (str.indexOf('audio') >= 0) { result = 'Audio'; }
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseLinuxUsb(usb) {
|
||||
const result = {};
|
||||
const lines = usb.split('\n');
|
||||
if (lines && lines.length && lines[0].indexOf('Device') >= 0) {
|
||||
const parts = lines[0].split(' ');
|
||||
result.bus = parseInt(parts[0], 10);
|
||||
if (parts[2]) {
|
||||
result.deviceId = parseInt(parts[2], 10);
|
||||
} else {
|
||||
result.deviceId = null;
|
||||
}
|
||||
} else {
|
||||
result.bus = null;
|
||||
result.deviceId = null;
|
||||
}
|
||||
const idVendor = util.getValue(lines, 'idVendor', ' ', true).trim();
|
||||
let vendorParts = idVendor.split(' ');
|
||||
vendorParts.shift();
|
||||
const vendor = vendorParts.join(' ');
|
||||
|
||||
const idProduct = util.getValue(lines, 'idProduct', ' ', true).trim();
|
||||
let productParts = idProduct.split(' ');
|
||||
productParts.shift();
|
||||
const product = productParts.join(' ');
|
||||
|
||||
const interfaceClass = util.getValue(lines, 'bInterfaceClass', ' ', true).trim();
|
||||
let interfaceClassParts = interfaceClass.split(' ');
|
||||
interfaceClassParts.shift();
|
||||
const usbType = interfaceClassParts.join(' ');
|
||||
|
||||
const iManufacturer = util.getValue(lines, 'iManufacturer', ' ', true).trim();
|
||||
let iManufacturerParts = iManufacturer.split(' ');
|
||||
iManufacturerParts.shift();
|
||||
const manufacturer = iManufacturerParts.join(' ');
|
||||
|
||||
result.id = (idVendor.startsWith('0x') ? idVendor.split(' ')[0].substr(2, 10) : '') + ':' + (idProduct.startsWith('0x') ? idProduct.split(' ')[0].substr(2, 10) : '');
|
||||
result.name = product;
|
||||
result.type = getLinuxUsbType(usbType, product);
|
||||
result.removable = null;
|
||||
result.vendor = vendor;
|
||||
result.manufacturer = manufacturer;
|
||||
result.maxPower = util.getValue(lines, 'MaxPower', ' ', true);
|
||||
result.serialNumber = null;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// bus
|
||||
// deviceId
|
||||
// id
|
||||
// name(product)
|
||||
// type(bInterfaceClass)
|
||||
// removable / hotplug
|
||||
// vendor
|
||||
// manufacturer
|
||||
// maxpower(linux)
|
||||
|
||||
function getDarwinUsbType(name) {
|
||||
let result = '';
|
||||
if (name.indexOf('camera') >= 0) { result = 'Camera'; }
|
||||
else if (name.indexOf('touch bar') >= 0) { result = 'Touch Bar'; }
|
||||
else if (name.indexOf('controller') >= 0) { result = 'Controller'; }
|
||||
else if (name.indexOf('headset') >= 0) { result = 'Audio'; }
|
||||
else if (name.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (name.indexOf('trackpad') >= 0) { result = 'Trackpad'; }
|
||||
else if (name.indexOf('sensor') >= 0) { result = 'Sensor'; }
|
||||
else if (name.indexOf('bthusb') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('bth') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('rfcomm') >= 0) { result = 'Bluetooth'; }
|
||||
else if (name.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
else if (name.indexOf(' hub') >= 0) { result = 'Hub'; }
|
||||
else if (name.indexOf('mouse') >= 0) { result = 'Mouse'; }
|
||||
else if (name.indexOf('mic') >= 0) { result = 'Microphone'; }
|
||||
else if (name.indexOf('removable') >= 0) { result = 'Storage'; }
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function parseDarwinUsb(usb, id) {
|
||||
const result = {};
|
||||
result.id = id;
|
||||
|
||||
usb = usb.replace(/ \|/g, '');
|
||||
usb = usb.trim();
|
||||
let lines = usb.split('\n');
|
||||
lines.shift();
|
||||
try {
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
lines[i] = lines[i].trim();
|
||||
lines[i] = lines[i].replace(/=/g, ':');
|
||||
if (lines[i] !== '{' && lines[i] !== '}' && lines[i + 1] && lines[i + 1].trim() !== '}') {
|
||||
lines[i] = lines[i] + ',';
|
||||
}
|
||||
lines[i] = lines[i].replace(': Yes,', ': "Yes",');
|
||||
lines[i] = lines[i].replace(': No,', ': "No",');
|
||||
}
|
||||
const usbObj = JSON.parse(lines.join('\n'));
|
||||
const removableDrive = usbObj['Built-In'].toLowerCase() !== 'yes' && usbObj['non-removable'].toLowerCase() === 'no';
|
||||
|
||||
result.bus = null;
|
||||
result.deviceId = null;
|
||||
result.id = usbObj['USB Address'] || null;
|
||||
result.name = usbObj['kUSBProductString'] || usbObj['USB Product Name'] || null;
|
||||
result.type = getDarwinUsbType((usbObj['kUSBProductString'] || usbObj['USB Product Name'] || '').toLowerCase() + (removableDrive ? ' removable' : ''));
|
||||
result.removable = usbObj['non-removable'].toLowerCase() === 'no';
|
||||
result.vendor = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
result.manufacturer = usbObj['kUSBVendorString'] || usbObj['USB Vendor Name'] || null;
|
||||
result.maxPower = null;
|
||||
result.serialNumber = usbObj['kUSBSerialNumberString'] || null;
|
||||
|
||||
if (result.name) {
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// function getWindowsUsbType(service) {
|
||||
// let result = ''
|
||||
// if (service.indexOf('usbhub3') >= 0) { result = 'Hub'; }
|
||||
// else if (service.indexOf('usbstor') >= 0) { result = 'Storage'; }
|
||||
// else if (service.indexOf('hidusb') >= 0) { result = 'Input'; }
|
||||
// else if (service.indexOf('usbccgp') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('usbxhci') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('usbehci') >= 0) { result = 'Controller'; }
|
||||
// else if (service.indexOf('kbdhid') >= 0) { result = 'Keyboard'; }
|
||||
// else if (service.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
// else if (service.indexOf('pointing') >= 0) { result = 'Mouse'; }
|
||||
// else if (service.indexOf('disk') >= 0) { result = 'Storage'; }
|
||||
// else if (service.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
// else if (service.indexOf('bthusb') >= 0) { result = ''; }
|
||||
// else if (service.indexOf('bth') >= 0) { result = ''; }
|
||||
// else if (service.indexOf('rfcomm') >= 0) { result = ''; }
|
||||
// return result;
|
||||
// }
|
||||
|
||||
function getWindowsUsbTypeCreation(creationclass, name) {
|
||||
let result = '';
|
||||
if (name.indexOf('storage') >= 0) { result = 'Storage'; }
|
||||
else if (name.indexOf('speicher') >= 0) { result = 'Storage'; }
|
||||
else if (creationclass.indexOf('usbhub') >= 0) { result = 'Hub'; }
|
||||
else if (creationclass.indexOf('storage') >= 0) { result = 'Storage'; }
|
||||
else if (creationclass.indexOf('usbcontroller') >= 0) { result = 'Controller'; }
|
||||
else if (creationclass.indexOf('keyboard') >= 0) { result = 'Keyboard'; }
|
||||
else if (creationclass.indexOf('pointing') >= 0) { result = 'Mouse'; }
|
||||
else if (creationclass.indexOf('disk') >= 0) { result = 'Storage'; }
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseWindowsUsb(lines, id) {
|
||||
const usbType = getWindowsUsbTypeCreation(util.getValue(lines, 'CreationClassName', ':').toLowerCase(), util.getValue(lines, 'name', ':').toLowerCase());
|
||||
|
||||
if (usbType) {
|
||||
const result = {};
|
||||
result.bus = null;
|
||||
result.deviceId = util.getValue(lines, 'deviceid', ':');
|
||||
result.id = id;
|
||||
result.name = util.getValue(lines, 'name', ':');
|
||||
result.type = usbType;
|
||||
result.removable = null;
|
||||
result.vendor = null;
|
||||
result.manufacturer = util.getValue(lines, 'Manufacturer', ':');
|
||||
result.maxPower = null;
|
||||
result.serialNumber = null;
|
||||
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function usb(callback) {
|
||||
|
||||
return new Promise((resolve) => {
|
||||
process.nextTick(() => {
|
||||
let result = [];
|
||||
if (_linux) {
|
||||
const cmd = 'export LC_ALL=C; lsusb -v 2>/dev/null; unset LC_ALL';
|
||||
exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
const parts = ('\n\n' + stdout.toString()).split('\n\nBus ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const usb = parseLinuxUsb(parts[i]);
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_darwin) {
|
||||
let cmd = 'ioreg -p IOUSB -c AppleUSBRootHubDevice -w0 -l';
|
||||
exec(cmd, { maxBuffer: 1024 * 1024 * 128 }, function (error, stdout) {
|
||||
if (!error) {
|
||||
const parts = (stdout.toString()).split(' +-o ');
|
||||
for (let i = 1; i < parts.length; i++) {
|
||||
const usb = parseDarwinUsb(parts[i]);
|
||||
if (usb) {
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
}
|
||||
if (_windows) {
|
||||
util.powerShell('Get-WmiObject CIM_LogicalDevice | where { $_.Description -match "^USB"}').then((stdout, error) => {
|
||||
if (!error) {
|
||||
const parts = stdout.toString().split(/\n\s*\n/);
|
||||
for (let i = 0; i < parts.length; i++) {
|
||||
const usb = parseWindowsUsb(parts[i].split('\n'), i);
|
||||
if (usb) {
|
||||
result.push(usb);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (callback) {
|
||||
callback(result);
|
||||
}
|
||||
resolve(result);
|
||||
});
|
||||
|
||||
// util.powerShell("gwmi Win32_USBControllerDevice |\%{[wmi]($_.Dependent)}").then(data => {
|
||||
|
||||
// const parts = data.toString().split(/\n\s*\n/);
|
||||
// for (let i = 0; i < parts.length; i++) {
|
||||
// const usb = parseWindowsUsb(parts[i].split('\n'), i)
|
||||
// if (usb) {
|
||||
// result.push(usb)
|
||||
// }
|
||||
// }
|
||||
// if (callback) {
|
||||
// callback(result);
|
||||
// }
|
||||
// resolve(result);
|
||||
// });
|
||||
}
|
||||
if (_sunos || _freebsd || _openbsd || _netbsd) {
|
||||
resolve(null);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
exports.usb = usb;
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -18,7 +18,7 @@ const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -22,7 +22,7 @@ const execSync = require('child_process').execSync;
|
||||
const util = require('util');
|
||||
|
||||
let _platform = process.platform;
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
const _freebsd = (_platform === 'freebsd');
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
// ----------------------------------------------------------------------------------
|
||||
// Description: System Information - library
|
||||
// for Node.js
|
||||
// Copyright: (c) 2014 - 2021
|
||||
// Copyright: (c) 2014 - 2022
|
||||
// Author: Sebastian Hildebrandt
|
||||
// ----------------------------------------------------------------------------------
|
||||
// License: MIT
|
||||
@ -20,7 +20,7 @@ const util = require('./util');
|
||||
|
||||
let _platform = process.platform;
|
||||
|
||||
const _linux = (_platform === 'linux');
|
||||
const _linux = (_platform === 'linux' || _platform === 'android');
|
||||
const _darwin = (_platform === 'darwin');
|
||||
const _windows = (_platform === 'win32');
|
||||
|
||||
|
||||
@ -90,7 +90,8 @@
|
||||
"freebsd",
|
||||
"openbsd",
|
||||
"netbsd",
|
||||
"sunos"
|
||||
"sunos",
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=8.0.0"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user