refactor and add modules directory
This commit is contained in:
1 parent
b272840eae
commit
8f5ad70ed3
13 files changed
+209
-90
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { Variable } from "astal";
|
||||
import GTop from "gi://GTop"
|
||||
|
||||
let previousCpuData = new GTop.glibtop_cpu();
|
||||
GTop.glibtop_get_cpu(previousCpuData);
|
||||
|
||||
const computeCPU = (): string => {
|
||||
const currentCpuData = new GTop.glibtop_cpu();
|
||||
GTop.glibtop_get_cpu(currentCpuData);
|
||||
|
||||
// Calculate the differences from the previous to current data
|
||||
const totalDiff = currentCpuData.total - previousCpuData.total;
|
||||
const idleDiff = currentCpuData.idle - previousCpuData.idle;
|
||||
|
||||
const cpuUsagePercentage = totalDiff > 0 ? ((totalDiff - idleDiff) / totalDiff) * 100 : 0;
|
||||
|
||||
previousCpuData = currentCpuData;
|
||||
|
||||
const cpuUsagePercentageString = " " + Math.floor(cpuUsagePercentage) + "%";
|
||||
|
||||
return cpuUsagePercentageString;
|
||||
}
|
||||
|
||||
export default function Cpu() {
|
||||
const cpu_usage = Variable<string>("").poll(5000, () =>
|
||||
computeCPU())
|
||||
|
||||
return <box className="cpu">
|
||||
<label
|
||||
className="Cpu"
|
||||
onDestroy={() => cpu_usage.drop()}
|
||||
label={cpu_usage()} />
|
||||
</box>
|
||||
}
|
||||
Reference in new issue
Block a user