fix: poll disk data, clipboard persist, fix disk display type

This commit is contained in:
2025-06-24 20:19:47 -07:00
parent 66eda1d7cc
commit 142f4f0dab
4 changed files with 25 additions and 9 deletions

View File

@@ -92,10 +92,10 @@ function Ram() {
</box>
}
let disk_space = Variable(get_disk_space())
let disk_space = Variable(get_disk_space()).poll(5000, () => get_disk_space())
function Disk() {
return <box className="status-box">
<label label={bind(disk_space).as((s) => `${s}GiB`)} />
<label label={bind(disk_space).as((s) => `${s}`)} />
</box>
}
@@ -106,7 +106,7 @@ function Battery() {
if (charging) {
return { label: `${full_percentage == 100 ? "FULL" : "CHR"}: ${full_percentage}%` }
}
return { label: `${full_percentage == 100 ? "FULL" : "BAT"}: ${full_percentage}` }
return { label: `${full_percentage == 100 ? "FULL" : "BAT"}: ${full_percentage}%` }
})
return <box className="status-box">

View File

@@ -1,5 +1,6 @@
import { GLib, Variable } from "astal";
import GTop from "gi://GTop";
import Wp05 from "gi://Wp";
type Snapshot = {
total: number;
@@ -35,12 +36,23 @@ export function get_ram_info() {
};
}
function format_bytes(bytes: number) {
let units = ["B", "KiB", "MiB", "GiB", "TiB"];
let i = 0;
let num: number = bytes;
while (num >= 1024 && i < units.length - 1) {
num /= 1024;
i++;
}
return `${num.toFixed(2)}${units[i]}`;
}
export function get_disk_space() {
const usage = new GTop.glibtop_fsusage();
GTop.glibtop_get_fsusage(usage, "/");
const free_bytes = usage.bavail * usage.block_size;
const free_gib = free_bytes / 1024 ** 3;
return free_gib.toFixed(2);
return format_bytes(free_bytes);
}