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