@daimazun/hardware-info 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/process-ops.js +16 -4
- package/package.json +1 -1
package/lib/process-ops.js
CHANGED
|
@@ -94,7 +94,7 @@ function findPidsByName(name) {
|
|
|
94
94
|
* - { pid: number|number[] }: 按 PID 杀
|
|
95
95
|
* - { port: number|number[], protocol?: 'tcp'|'udp'|'all' }: 按端口杀
|
|
96
96
|
* - { name: string|string[] }: 按进程名杀
|
|
97
|
-
* @returns {Promise<{ok: boolean, killed: number, failed: number, pids?: number[], message?: string}>}
|
|
97
|
+
* @returns {Promise<{ok: boolean, killed: number, failed: number, pids?: number[], failedDetails?: Array<{pid: number|null, reason: string}>, message?: string}>}
|
|
98
98
|
*/
|
|
99
99
|
async function killProcess(input) {
|
|
100
100
|
let pids = [];
|
|
@@ -160,6 +160,7 @@ async function killProcess(input) {
|
|
|
160
160
|
const fkill = await getFkill();
|
|
161
161
|
let killed = 0;
|
|
162
162
|
let failed = 0;
|
|
163
|
+
const failedDetails = [];
|
|
163
164
|
|
|
164
165
|
try {
|
|
165
166
|
// fkill 支持一次传 PID 数组,内部并行处理
|
|
@@ -169,27 +170,38 @@ async function killProcess(input) {
|
|
|
169
170
|
// fkill 失败时抛 AggregateError,errors 数组包含每个 PID 的具体错误
|
|
170
171
|
if (e.name === 'AggregateError' && Array.isArray(e.errors)) {
|
|
171
172
|
for (const err of e.errors) {
|
|
172
|
-
const msg = String(err)
|
|
173
|
+
const msg = String(err);
|
|
174
|
+
const lowerMsg = msg.toLowerCase();
|
|
175
|
+
// 从错误消息里提取 PID:格式如 "Killing process 1234 failed: 拒绝访问"
|
|
176
|
+
const pidMatch = msg.match(/Killing process\s+(\d+)\s+failed:\s*(.+)/i);
|
|
177
|
+
const pid = pidMatch ? parseInt(pidMatch[1], 10) : null;
|
|
178
|
+
const reason = pidMatch ? pidMatch[2].trim() : msg;
|
|
173
179
|
// 进程已不存在,视为达成目标
|
|
174
|
-
if (
|
|
180
|
+
if (lowerMsg.includes("doesn't exist") || lowerMsg.includes('not found') || lowerMsg.includes('不存在')) {
|
|
175
181
|
killed++;
|
|
176
182
|
} else {
|
|
177
183
|
failed++;
|
|
184
|
+
failedDetails.push({ pid, reason });
|
|
178
185
|
}
|
|
179
186
|
}
|
|
180
187
|
} else {
|
|
188
|
+
// 非 AggregateError(如 fkill 加载失败、taskkill 不存在等):全部标记失败
|
|
181
189
|
failed = list.length;
|
|
190
|
+
for (const pid of list) {
|
|
191
|
+
failedDetails.push({ pid, reason: e.message || String(e) });
|
|
192
|
+
}
|
|
182
193
|
}
|
|
183
194
|
}
|
|
184
195
|
|
|
185
196
|
if (killed > 0) {
|
|
186
|
-
return { ok: true, killed, failed, pids: list };
|
|
197
|
+
return { ok: true, killed, failed, pids: list, failedDetails };
|
|
187
198
|
}
|
|
188
199
|
return {
|
|
189
200
|
ok: false,
|
|
190
201
|
killed: 0,
|
|
191
202
|
failed,
|
|
192
203
|
pids: list,
|
|
204
|
+
failedDetails,
|
|
193
205
|
message: '结束失败:权限不足或进程受系统保护,请以管理员身份运行'
|
|
194
206
|
};
|
|
195
207
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daimazun/hardware-info",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Cross-platform hardware information & monitor library — CPU temperature/load/clock/power, memory, disk, motherboard, GPU via OpenHardwareMonitor (Windows) with Linux/macOS support planned",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|