[AGS] SysInfo: Improve performance

This commit is contained in:
Janis Hutz 2025-04-26 15:07:49 +02:00
parent 2fd32da1b2
commit b4b8d04e6a

View File

@ -1,4 +1,4 @@
import { exec, interval, Variable } from "astal"; import { exec, execAsync, interval, Variable } from "astal";
import { Gtk } from "astal/gtk4"; import { Gtk } from "astal/gtk4";
const FETCH_INTERVAL = 2000; const FETCH_INTERVAL = 2000;
@ -34,8 +34,8 @@ const refreshStats = (): Stats => {
`cat /sys/class/drm/${gpuName}/device/mem_info_vram_used`, `cat /sys/class/drm/${gpuName}/device/mem_info_vram_used`,
), ),
) / ) /
1024 / 1024 /
1024, 1024,
) + "MiB", ) + "MiB",
availableVRAM: availableVRAM:
Math.round( Math.round(
@ -44,8 +44,8 @@ const refreshStats = (): Stats => {
`cat /sys/class/drm/${gpuName}/device/mem_info_vram_total`, `cat /sys/class/drm/${gpuName}/device/mem_info_vram_total`,
), ),
) / ) /
1024 / 1024 /
1024, 1024,
) + "MiB", ) + "MiB",
}; };
@ -109,7 +109,7 @@ Kernel: ${stats.kernel}`;
></label> ></label>
<Gtk.Separator marginTop={10}></Gtk.Separator> <Gtk.Separator marginTop={10}></Gtk.Separator>
<button <button
onClicked={() => exec( `/bin/sh -c "kitty --hold fish -c 'fastfetch'"` )} onClicked={() => exec(`/bin/sh -c "kitty --hold fish -c 'fastfetch'"`)}
child={ child={
<label label={"View FastFetch"}></label> <label label={"View FastFetch"}></label>
}></button> }></button>
@ -128,24 +128,23 @@ const SystemInformationPanel = () => {
const sysInfoFetcher = () => { const sysInfoFetcher = () => {
if (enabled) { if (enabled) {
if (availableFeatures.cpu) { if (availableFeatures.cpu) {
cpuUtil.set( execAsync(`/bin/fish -c cpu-utilization`).then(v => {
"" + cpuUtil.set("" + Math.round(parseFloat(v)));
Math.round( }).catch( e => {
parseFloat(exec(`/bin/fish -c cpu-utilization`)), console.error( e );
), } );
);
} }
if (availableFeatures.ram) { if (availableFeatures.ram) {
ramUtil.set( execAsync(
"" + `/bin/bash -c "free | awk '/Mem:/ {print $3 \\" \\" $2}'"`,
Math.round( ).then( v => {
parseFloat( const util = parseInt( v.split( ' ' )[ 0 ] );
exec( const available = parseInt( v.split( ' ' )[ 1 ] );
`/bin/bash -c "free | awk '/Mem/ { printf(\\"%.2f\\\\n\\", ($3/$2)*100) }'"`, 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( ramUsed.set(
exec( exec(
`/bin/bash -c \"free -h | awk '/^Mem:/ {print $3 \\" used of \\" $2}'\"`, `/bin/bash -c \"free -h | awk '/^Mem:/ {print $3 \\" used of \\" $2}'\"`,