[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;
@ -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}'\"`,