diff --git a/config/astal/components/bar/modules/SystemInfo.tsx b/config/astal/components/bar/modules/SystemInfo.tsx index 0da2f3e..d4140f0 100644 --- a/config/astal/components/bar/modules/SystemInfo.tsx +++ b/config/astal/components/bar/modules/SystemInfo.tsx @@ -1,88 +1,6 @@ -import { exec, execAsync, interval, Variable } from "astal"; +import { exec } from "astal"; import { Gtk } from "astal/gtk4"; - -const FETCH_INTERVAL = 2000; - -const cpuUtil = Variable("0%"); -const ramUtil = Variable("0%"); -const ramUsed = Variable("0MiB"); -const gpuUtil = Variable("0%"); -let gpuName = "card1"; -let enabled = false; - -const refreshStats = (): Stats => { - gpuName = exec(`/bin/bash -c "ls /sys/class/drm/ | grep '^card[0-9]*$'"`); - const cpuNameInSensors = "CPUTIN"; - const stats = { - kernel: exec("uname -sr"), - cpuTemp: exec( - `/bin/bash -c "sensors | grep -m1 ${cpuNameInSensors} | awk '{print $2}'"`, - ), - cpuClk: exec( - `awk '/cpu MHz/ {sum+=$4; ++n} END {print sum/n " MHz"}' /proc/cpuinfo`, - ), - gpuTemp: exec( - `/bin/bash -c "sensors | grep -E 'edge' | awk '{print $2}'"`, - ), - gpuClk: exec( - `/bin/bash -c "cat /sys/class/drm/${gpuName}/device/pp_dpm_sclk | grep '\\*' | awk '{print $2 $3}'"`, - ), - vram: - Math.round( - parseInt( - exec( - `cat /sys/class/drm/${gpuName}/device/mem_info_vram_used`, - ), - ) / - 1024 / - 1024, - ) + "MiB", - availableVRAM: - Math.round( - parseInt( - exec( - `cat /sys/class/drm/${gpuName}/device/mem_info_vram_total`, - ), - ) / - 1024 / - 1024, - ) + "MiB", - }; - - return stats; -}; - -const systemStats: Variable = Variable(refreshStats()); - -const availableFeatures = { - cpu: true, - ram: true, -}; - -const featureTest = () => { - // Check if awk & sed are available - try { - exec("awk -V"); - exec("sed --version"); - enabled = true; - } catch (e) { - printerr( - "[ SysInfo ] AWK or SED missing! No system info will be available", - ); - enabled = false; - return; - } - - // Check if mpstat is available - try { - exec("mpstat -V"); - } catch (e) { - availableFeatures.cpu = false; - printerr( - "[ SysInfo ] Feature Test for CPU info failed. mpstat from the sysstat package missing!", - ); - } -}; +import sysinfo from "../sysinfo"; const info = () => { return ( @@ -96,12 +14,12 @@ const info = () => { vexpand halign={Gtk.Align.START} hexpand - label={ramUsed(used => { - return "RAM: " + used + ` (${ramUtil.get()}%)`; + label={sysinfo.ramUsed(used => { + return "RAM: " + used + ` (${sysinfo.ramUtil.get()}%)`; })} >