import si from "systeminformation";
import os from "os";
export async function getSystemInfo() {
try {
const osInfo = await si.osInfo();
const system = await si.system();
const uuid = await si.uuid();
return {
platform: os.platform(),
type: os.type(),
release: os.release(),
version: os.version(),
arch: os.arch(),
hostname: os.hostname(),
uptime: os.uptime(),
// 详细系统信息
distro: osInfo.distro,
codename: osInfo.codename,
kernel: osInfo.kernel,
build: osInfo.build,
// 系统制造商信息
manufacturer: system.manufacturer,
model: system.model,
serial: system.serial,
// UUID
uuid: uuid.os,
// 用户信息
username: os.userInfo().username,
homedir: os.homedir(),
tmpdir: os.tmpdir(),
};
} catch (error) {
if (error instanceof Error) {
throw new Error(`获取系统信息失败: ${error.message}`);
}
throw error;
}
}