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