fix: poll disk data, clipboard persist, fix disk display type
This commit is contained in:
@@ -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">
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user