You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/hydro/lib/sysinfo.ts

63 lines
2.1 KiB
TypeScript

import systeminformation from 'systeminformation';
import { size } from './misc';
const cache = {
mid: '', cpu: '', osinfo: '', flags: '',
};
export async function get() {
const [Cpu, Memory, OsInfo, CurrentLoad, CpuFlags, CpuTemp, Battery] = await Promise.all([
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' : ''}`;
4 years ago
const mid = OsInfo.serial;
cache.cpu = cpu;
cache.osinfo = osinfo;
cache.flags = flags;
4 years ago
cache.mid = mid;
return {
4 years ago
mid, cpu, memory, osinfo, load, flags, CpuTemp, battery,
};
}
export async function update(): Promise<[string, any, any]> {
const [Memory, CurrentLoad, CpuTemp, Battery] = await Promise.all([
systeminformation.mem(),
systeminformation.currentLoad(),
systeminformation.cpuTemperature(),
systeminformation.battery(),
]);
const {
4 years ago
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' : ''}`;
return [
4 years ago
mid,
{
memory, load, battery, CpuTemp,
},
{
4 years ago
mid, cpu, memory, osinfo, load, flags, battery, CpuTemp,
},
];
}
global.Hydro.lib.sysinfo = { get, update };