diff --git a/config/astal/components/bar/modules/SystemInfo.tsx b/config/astal/components/bar/modules/SystemInfo.tsx index 33c02bf..0da2f3e 100644 --- a/config/astal/components/bar/modules/SystemInfo.tsx +++ b/config/astal/components/bar/modules/SystemInfo.tsx @@ -1,4 +1,4 @@ -import { exec, interval, Variable } from "astal"; +import { exec, execAsync, interval, Variable } from "astal"; import { Gtk } from "astal/gtk4"; const FETCH_INTERVAL = 2000; @@ -34,8 +34,8 @@ const refreshStats = (): Stats => { `cat /sys/class/drm/${gpuName}/device/mem_info_vram_used`, ), ) / - 1024 / - 1024, + 1024 / + 1024, ) + "MiB", availableVRAM: Math.round( @@ -44,8 +44,8 @@ const refreshStats = (): Stats => { `cat /sys/class/drm/${gpuName}/device/mem_info_vram_total`, ), ) / - 1024 / - 1024, + 1024 / + 1024, ) + "MiB", }; @@ -109,7 +109,7 @@ Kernel: ${stats.kernel}`; > @@ -128,24 +128,23 @@ const SystemInformationPanel = () => { const sysInfoFetcher = () => { if (enabled) { if (availableFeatures.cpu) { - cpuUtil.set( - "" + - Math.round( - parseFloat(exec(`/bin/fish -c cpu-utilization`)), - ), - ); + execAsync(`/bin/fish -c cpu-utilization`).then(v => { + cpuUtil.set("" + Math.round(parseFloat(v))); + }).catch( e => { + console.error( e ); + } ); } if (availableFeatures.ram) { - ramUtil.set( - "" + - Math.round( - parseFloat( - exec( - `/bin/bash -c "free | awk '/Mem/ { printf(\\"%.2f\\\\n\\", ($3/$2)*100) }'"`, - ), - ), - ), - ); + execAsync( + `/bin/bash -c "free | awk '/Mem:/ {print $3 \\" \\" $2}'"`, + ).then( v => { + const util = parseInt( v.split( ' ' )[ 0 ] ); + const available = parseInt( v.split( ' ' )[ 1 ] ); + ramUtil.set( "" + Math.round( available / util ) ); + ramUsed.set( `${Math.round( util / 1024 / 1024 )}MiB used of ${Math.round( available / 1024 / 1024 )}MiB` ); + } ).catch( e => { + console.error( e ); + } ); ramUsed.set( exec( `/bin/bash -c \"free -h | awk '/^Mem:/ {print $3 \\" used of \\" $2}'\"`,