feat: add statsDaemon.interval setting, pass --interval to nova-stats

This commit is contained in:
Damocles 2026-04-15 19:01:29 +02:00
parent c8d71bd871
commit 937ae5af2e
4 changed files with 35 additions and 3 deletions

View file

@ -89,6 +89,9 @@ QtObject {
property var overviewBackdrop: ({ property var overviewBackdrop: ({
enable: true enable: true
}) })
property var statsDaemon: ({
interval: -1
})
property FileView _file: FileView { property FileView _file: FileView {
path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/nova-shell/modules.json" path: (Quickshell.env("XDG_CONFIG_HOME") || (Quickshell.env("HOME") + "/.config")) + "/nova-shell/modules.json"

View file

@ -29,7 +29,10 @@ QtObject {
// nova-stats stream (cpu + mem) // nova-stats stream (cpu + mem)
property var _statsProc: Process { property var _statsProc: Process {
running: true running: true
command: ["nova-stats"] command: {
const ms = M.Modules.statsDaemon.interval;
return ms > 0 ? ["nova-stats", "--interval", ms.toString()] : ["nova-stats"];
}
stdout: SplitParser { stdout: SplitParser {
splitMarker: "\n" splitMarker: "\n"
onRead: line => { onRead: line => {

View file

@ -169,6 +169,17 @@ in
}; };
} }
); );
statsDaemon = lib.mkOption {
default = { };
description = "Configuration for the nova-stats daemon.";
type = lib.types.submodule {
options.interval = lib.mkOption {
type = lib.types.int;
default = -1;
description = "nova-stats polling interval in milliseconds (-1 = use binary default of 1s).";
};
};
};
}; };
theme = lib.mkOption { theme = lib.mkOption {

View file

@ -159,7 +159,22 @@ fn emit_mem(out: &mut impl Write) {
} }
} }
fn parse_interval_ms() -> u64 {
let args: Vec<String> = std::env::args().collect();
let mut i = 1;
while i < args.len() {
if args[i] == "--interval" {
if let Some(ms) = args.get(i + 1).and_then(|s| s.parse().ok()) {
return ms;
}
}
i += 1;
}
1000
}
fn main() { fn main() {
let interval = Duration::from_millis(parse_interval_ms());
let stdout = io::stdout(); let stdout = io::stdout();
let mut out = io::BufWriter::new(stdout.lock()); let mut out = io::BufWriter::new(stdout.lock());
let mut prev: Vec<Sample> = vec![]; let mut prev: Vec<Sample> = vec![];
@ -181,8 +196,8 @@ fn main() {
tick += 1; tick += 1;
let elapsed = t0.elapsed(); let elapsed = t0.elapsed();
if elapsed < Duration::from_secs(1) { if elapsed < interval {
thread::sleep(Duration::from_secs(1) - elapsed); thread::sleep(interval - elapsed);
} }
} }
} }