From 68b7830d5b20653d2335037814ee94e6f4fd495d Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Wed, 23 Oct 2024 16:50:55 +0200 Subject: WIP: Add disk space support Currently disk space is wrong due to it using stat and reading the size of the folder (4096). Need to use smth like statvfs somehow... --- cmd/statusdaemon/main.ha | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/statusdaemon/main.ha b/cmd/statusdaemon/main.ha index 1356d32..63adac7 100644 --- a/cmd/statusdaemon/main.ha +++ b/cmd/statusdaemon/main.ha @@ -35,6 +35,7 @@ type status = struct { clock: clock, host: hostname, generics: []generic, + disk: disk, }; type section = struct { @@ -80,10 +81,14 @@ export fn main() void = { ... }; - const clocktimer = ev::newtimer(&loop, &clocktimerf, time::clock::MONOTONIC)!; - ev::timer_configure(clocktimer, 1 * time::SECOND, 1 * time::SECOND); + const timer = ev::newtimer(&loop, &nativetimerf, time::clock::MONOTONIC)!; + ev::timer_configure(timer, 1 * time::SECOND, 1 * time::SECOND); + ev::setuser(timer, &state); + + //const alltimer = ev::newtimer(&loop, &alltimerf, time::clock::MONOTONIC)!; + //ev::timer_configure(alltimer, 10 * time::SECOND, 10 * time::SECOND); + //ev::setuser(alltimer, &state); - ev::setuser(clocktimer, &state); ev::setuser(sock, &state); ev::accept(sock, &accept); @@ -103,6 +108,7 @@ fn newstatus() (status | io::error | utf8::invalid) = { generics = alloc([ buildgeneric("/home/jhurst/.local/share/statusbar/vol.sh"), ]), + disk = builddisk("/"), }; }; @@ -112,6 +118,22 @@ fn finishstatus(status: *status) void = { finishgeneric(gen); }; free(status.generics); + finishdisk(&status.disk); +}; + +fn alltimerf(file: *ev::file) void = { + let server = ev::getuser(file): *server; + for (let gen &.. server.status.generics) { + updategeneric(gen)!; + }; + printstatus(server.status); +}; + +fn nativetimerf(file: *ev::file) void = { + let server = ev::getuser(file): *server; + updateclock(&server.status.clock)!; + updatedisk(&server.status.disk); + printstatus(server.status); }; fn buildhostname() hostname = { @@ -140,6 +162,7 @@ fn getstatus(state: *status) str = { }; memio::concat(&st, state.host.section.label, state.host.value, " | ", + state.disk.section.label, state.disk.value, " | ", state.clock.section.label, state.clock.value, "\n" )!; //const s = strings::concat( -- cgit v1.2.3