Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export async function legacyJsonOutput(results: BenchmarkResult[]):
Promise {
// TODO Add git info.
const battery = await systeminformation.battery();
const cpu = await systeminformation.cpu();
const currentLoad = await systeminformation.currentLoad();
const memory = await systeminformation.mem();
return {
benchmarks: results,
datetime: new Date().toISOString(),
system: {
cpu: {
manufacturer: cpu.manufacturer,
model: cpu.model,
family: cpu.family,
speed: cpu.speed,
cores: cpu.cores,
},
load: {
average: currentLoad.avgload,
export async function dynamicInfo(): Promise {
const osData = {
hostname: os.hostname(),
uptime: os.uptime(),
freemem: os.freemem(),
totalmem: os.totalmem(),
cpus: os.cpus(),
loadavg: os.loadavg()
}
const promises = [
si.battery(),
si.graphics(),
si.osInfo(),
si.fsSize(),
si.cpuTemperature()
];
const [battery, graphics, osInfo, fsSize, cpuTemp] = await Promise.all(promises);
return {
...osData,
battery,
graphics,
osInfo,
fsSize,
cpuTemp
};
async function systeminfo() {
const info = {};
await Promise.all([
si.battery().then(r => info.battery = r),
si.cpu().then(r => info.cpu = r),
si.osInfo().then(r => info.osInfo = r),
]);
return info;
}
function updateBattery() {
return si.battery().then(data => {
if (!data.model) {
clearInterval(batteryTimer);
return;
}
let icon = Math.round(data.percent / 10) * 10;
if (icon === 100) icon = "battery";
else if (icon === 0) icon = "battery-outline";
else icon = "battery-" + icon;
if (data.ischarging) icon = icon.replace("battery", "battery-charging");
let isPerc = !!Registry.get("system.showBatteryPercentage");
let iconSize = isPerc ? 18 : 24;
let hours = Math.trunc(data.timeremaining / 60);
let minutes = data.timeremaining - Math.trunc(data.timeremaining / 60) * 60;
let time = hours > 0 ? hours + " hours" + (minutes > 0 ? " " + minutes + " minutes" : "") : (minutes > 0 ? minutes + " minutes" : "Not available");
let status = (data.percent > 49 || data.ischarging) ? "success" : (data.percent > 19 ? "warning" : "danger");
button.icon.className = `mdi mdi-${iconSize}px d-flex lh-${iconSize} mdi-${icon}`;