diff --git a/kit/package-lock.json b/kit/package-lock.json index 929c74e..f395e0e 100644 --- a/kit/package-lock.json +++ b/kit/package-lock.json @@ -10,14 +10,13 @@ "dependencies": { "auto-launch": "^5.0.6", "cross-port-killer": "^1.4.0", - "diskusage-ng": "^1.0.4", "extract-zip": "^2.0.1", "get-port": "^7.0.0", "json5": "^2.2.3", "log4js": "^6.9.1", "physical-cpu-count": "^2.0.0", "sm-crypto": "^0.3.13", - "systeminformation": "^5.25.11", + "systeminformation": "^5.30.6", "webdav": "^5.3.1" }, "bin": { @@ -158,15 +157,6 @@ } } }, - "node_modules/diskusage-ng": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/diskusage-ng/-/diskusage-ng-1.0.4.tgz", - "integrity": "sha512-30qT0Bn2dNGii6dAXllGgYRaIt+7gPhwCJks+byhutkCOCgsqfqvXmAV2zTDOvU1ylnGHUjZMMaKhM95FyQQrg==", - "license": "MIT", - "engines": { - "node": ">=8.8.0" - } - }, "node_modules/end-of-stream": { "version": "1.4.4", "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", diff --git a/kit/package.json b/kit/package.json index 42e0485..8e483b6 100644 --- a/kit/package.json +++ b/kit/package.json @@ -14,14 +14,13 @@ "dependencies": { "auto-launch": "^5.0.6", "cross-port-killer": "^1.4.0", - "diskusage-ng": "^1.0.4", "extract-zip": "^2.0.1", "get-port": "^7.0.0", "json5": "^2.2.3", "log4js": "^6.9.1", "physical-cpu-count": "^2.0.0", "sm-crypto": "^0.3.13", - "systeminformation": "^5.25.11", + "systeminformation": "^5.30.6", "webdav": "^5.3.1" } } diff --git a/kit/src/index.js b/kit/src/index.js index ca7827c..38fb732 100644 --- a/kit/src/index.js +++ b/kit/src/index.js @@ -138,15 +138,19 @@ parser.addCmdLine("platform", "平台信息", function (cli) { } table.push({ '项' : 'Mem ' + k, '值' : info.memory[k]}) } - for ( let k in info.disk ){ - if ( k.endsWith("Size") ) { - continue; - } - table.push({ '项' : 'Disk' + k, '值' : info.disk[k]}) - } console.table(table); + const disks = info.disk; + disks.forEach(disk => { + console.log(`磁盘 ${disk.mount}:`); + console.log(` 总空间: ${(disk.size / 1024 / 1024 / 1024).toFixed(2)} GB`); + console.log(` 已用空间: ${(disk.used / 1024 / 1024 / 1024).toFixed(2)} GB`); + console.log(` 可用空间: ${(disk.available / 1024 / 1024 / 1024).toFixed(2)} GB`); + console.log(` 使用率: ${disk.use}%`); + }); console.log( JSON.stringify(info, null, 4)); + + }).catch(error => { console.error('Error getting device information:', error); }); diff --git a/kit/src/platform.js b/kit/src/platform.js index af0b62b..222bcbe 100644 --- a/kit/src/platform.js +++ b/kit/src/platform.js @@ -1,6 +1,5 @@ const os = require('os'); -const diskusage = require('diskusage-ng'); -const { physicalCpuCount } = require('physical-cpu-count'); +const si = require('systeminformation'); const { formatBytes } = require("./util/convutil") const { exec } = require('child_process'); const { promisify } = require('util'); @@ -14,6 +13,7 @@ const readFilePromise = promisify(fs.readFile); // 获取操作系统信息 async function getOSInfo() { + return { type: os.type(), platform: os.platform(), @@ -26,6 +26,7 @@ async function getOSInfo() { // 获取 CPU 信息 function getCPUInfo() { const cpus = os.cpus(); + const physicalCpuCount = require('physical-cpu-count') return { model: cpus[0].model, speed: cpus[0].speed, @@ -47,38 +48,13 @@ function getMemoryInfo() { }); } -// 获取硬盘信息 -async function getDiskInfo() { - try { - const path = os.platform() === 'win32' ? 'C:' : '/'; - return new Promise(function (resolve, reject) { - diskusage(path, function (err, usage) { - if (err) { - console.error('Error getting disk information:', err); - reject(err); - } - resolve({ - totalSize: usage.total, - freeSize: usage.available, - total : formatBytes(usage.total), - free : formatBytes(usage.available), - }); - }); - }) - - - } catch (error) { - console.error('Error getting disk information:', error); - return null; - } -} // 主函数,调用上述函数获取所有信息 async function getAllDeviceInfo() { const osInfo = await getOSInfo(); const cpuInfo = getCPUInfo(); const memoryInfo = getMemoryInfo(); - const diskInfo = await getDiskInfo(); + const diskInfo = await si.fsSize(); return { os: osInfo, @@ -131,6 +107,5 @@ module.exports = { getOSInfo, getCPUInfo, getMemoryInfo, - getDiskInfo, getAllDeviceInfo };