import app from "ags/gtk3/app" import { Astal, Gtk } from "ags/gtk3" import { createPoll } from "ags/time" import { shell } from "../lib/utils" export const SYSMONITOR_WINDOW = "sys-monitor" let previousIdle = 0 let previousTotal = 0 const cpuUsage = createPoll( 0, 2000, shell("grep '^cpu ' /proc/stat"), (stdout) => { const values = stdout.trim().split(/\s+/).slice(1).map(Number) const idle = (values[3] || 0) + (values[4] || 0) const total = values.reduce((sum, value) => sum + value, 0) const idleDelta = idle - previousIdle const totalDelta = total - previousTotal previousIdle = idle previousTotal = total if (totalDelta <= 0) return 0 return Math.round((1 - idleDelta / totalDelta) * 100) }, ) type Usage = { percent: number; used: string; total: string } const memory = createPoll( { percent: 0, used: "0", total: "0" }, 2000, shell("free -m | awk '/^Mem:/ {print $3\" \"$2}'"), (stdout) => { const [used, total] = stdout.trim().split(/\s+/).map(Number) if (!total) return { percent: 0, used: "0", total: "0" } return { percent: Math.round((used / total) * 100), used: `${(used / 1024).toFixed(1)}G`, total: `${(total / 1024).toFixed(1)}G`, } }, ) const disk = createPoll( { percent: 0, used: "0", total: "0" }, 30000, shell("df -h --output=pcent,used,size / | tail -1"), (stdout) => { const [percent, used, total] = stdout.trim().split(/\s+/) return { percent: Number(percent.replace("%", "")) || 0, used: used || "0", total: total || "0", } }, ) const temperature = createPoll( 0, 2000, shell("cat /sys/class/thermal/thermal_zone0/temp 2>/dev/null || echo 0"), (stdout) => Math.round(Number(stdout.trim()) / 1000) || 0, ) function Metric({ icon, name, percent, detail, }: { icon: string name: string percent: any detail: any }) { return ( value / 100)} /> ) } export default function SysMonitor() { const { TOP, RIGHT } = Astal.WindowAnchor return ( ) }