System Resources
Monitor system resources like CPU, memory, and battery.
System Resources
The systemResources module allows you to access real-time system information.
Usage
import { systemResources } from "@buildcosmo/widget";getSystemCpu()
Retrieves the current CPU usage percentage.
Usage
const cpuUsage = await systemResources.getSystemCpu();
console.log(`CPU Usage: ${cpuUsage}%`);Returns
Promise<number>: The current CPU usage as a percentage (0-100).
getSystemMemory()
Retrieves the current memory usage.
Usage
const [used, total] = await systemResources.getSystemMemory();
const usedGB = (used / (1024 * 1024 * 1024)).toFixed(2);
const totalGB = (total / (1024 * 1024 * 1024)).toFixed(2);
console.log(`Memory: ${usedGB}GB / ${totalGB}GB`);Returns
Promise<[number, number]>: A tuple containing:used: Used memory in bytes.total: Total memory in bytes.
getSystemBattery()
Retrieves the current battery status.
Usage
const [percentage, isCharging, remainingTime] = await systemResources.getSystemBattery();
console.log(`Battery: ${percentage}%`);
console.log(`Charging: ${isCharging}`);
console.log(`Time remaining: ${remainingTime} minutes`);Returns
Promise<[number, boolean, number]>: A tuple containing:percentage: Battery level as a percentage (0-100).isCharging:trueif the device is plugged in,falseotherwise.remainingTime: Estimated time remaining in minutes. Returns-1if unknown.