mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-21 01:46:28 +08:00
core: update detailed status
This commit is contained in:
1 parent
51ce9f80d5
commit
b9e08c7e93
15 files changed
+142
-99
No files matched your search
@@ -1,60 +1,54 @@
|
||||
import systeminformation from 'systeminformation';
|
||||
import { size } from './misc';
|
||||
import systeminformation, { Systeminformation } from 'systeminformation';
|
||||
|
||||
const cache = {
|
||||
mid: '', cpu: '', osinfo: '', flags: '',
|
||||
};
|
||||
const cache: any = {};
|
||||
|
||||
export async function get() {
|
||||
const [Cpu, Memory, OsInfo, CurrentLoad, CpuFlags, CpuTemp, Battery] = await Promise.all([
|
||||
export interface StatusUpdate {
|
||||
memory: Systeminformation.MemData;
|
||||
load: Systeminformation.CurrentLoadData;
|
||||
battery: Systeminformation.BatteryData;
|
||||
CpuTemp: Systeminformation.CpuTemperatureData;
|
||||
}
|
||||
|
||||
export interface StatusFull extends StatusUpdate {
|
||||
mid: string;
|
||||
cpu: Systeminformation.CpuData;
|
||||
osinfo: Systeminformation.OsData;
|
||||
}
|
||||
|
||||
export async function get(): Promise<StatusFull> {
|
||||
const [uuid, cpu, memory, osinfo, load, CpuTemp, battery] = await Promise.all([
|
||||
systeminformation.uuid(),
|
||||
systeminformation.cpu(),
|
||||
systeminformation.mem(),
|
||||
systeminformation.osInfo(),
|
||||
systeminformation.currentLoad(),
|
||||
systeminformation.cpuFlags(),
|
||||
systeminformation.cpuTemperature(),
|
||||
systeminformation.battery(),
|
||||
]);
|
||||
const cpu = `${Cpu.manufacturer} ${Cpu.brand}`;
|
||||
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
|
||||
const osinfo = `${OsInfo.distro} ${OsInfo.release} ${OsInfo.codename} ${OsInfo.kernel} ${OsInfo.arch}`;
|
||||
const load = `${CurrentLoad.avgLoad}`;
|
||||
const flags = CpuFlags;
|
||||
let battery;
|
||||
if (!Battery.hasBattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
|
||||
const mid = OsInfo.serial;
|
||||
const mid = uuid.hardware;
|
||||
cache.cpu = cpu;
|
||||
cache.osinfo = osinfo;
|
||||
cache.flags = flags;
|
||||
cache.mid = mid;
|
||||
return {
|
||||
mid, cpu, memory, osinfo, load, flags, CpuTemp, battery,
|
||||
mid, cpu, memory, osinfo, load, CpuTemp, battery,
|
||||
};
|
||||
}
|
||||
|
||||
export async function update(): Promise<[string, any, any]> {
|
||||
const [Memory, CurrentLoad, CpuTemp, Battery] = await Promise.all([
|
||||
export async function update(): Promise<[string, StatusUpdate, StatusFull]> {
|
||||
const [memory, load, CpuTemp, battery] = await Promise.all([
|
||||
systeminformation.mem(),
|
||||
systeminformation.currentLoad(),
|
||||
systeminformation.cpuTemperature(),
|
||||
systeminformation.battery(),
|
||||
]);
|
||||
const {
|
||||
mid, cpu, osinfo, flags,
|
||||
} = cache;
|
||||
const memory = `${size(Memory.active)}/${size(Memory.total)}`;
|
||||
const load = `${CurrentLoad.avgLoad}`;
|
||||
let battery;
|
||||
if (!Battery.hasBattery) battery = 'No battery';
|
||||
else battery = `${Battery.type} ${Battery.model} ${Battery.percent}%${Battery.isCharging ? ' Charging' : ''}`;
|
||||
const { mid, cpu, osinfo } = cache;
|
||||
return [
|
||||
mid,
|
||||
{
|
||||
memory, load, battery, CpuTemp,
|
||||
},
|
||||
{
|
||||
mid, cpu, memory, osinfo, load, flags, battery, CpuTemp,
|
||||
mid, cpu, memory, osinfo, load, battery, CpuTemp,
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user