mod backend;
mod config;
use backend::{Backend, DisplayServer, detect};
use config::{Args, Config, parse_args};
use std::thread;
use std::time::Duration;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let Args {
config_path,
overrides,
count,
} = parse_args().unwrap_or_else(|e| {
eprintln!("augenblick: {e}");
std::process::exit(1);
});
let mut cfg = Config::load(&config_path);
cfg.apply_overrides(&overrides);
let backend: Box<dyn Backend> = match detect()? {
#[cfg(not(target_os = "macos"))]
DisplayServer::Wayland => {
println!("augenblick: detected Wayland");
Box::new(backend::wayland::WaylandBackend::new()?)
}
DisplayServer::X11 => {
println!("augenblick: detected X11");
Box::new(backend::x11::X11Backend::new()?)
}
};
let colors: Vec<String> =
cfg.colors().iter().map(|c| format!("#{c:06X}")).collect();
println!(
"augenblick: blink every {} seconds, movement {}, animation {} frames, hold {} ms, fade {} ms, color {}",
cfg.sleep_secs(),
cfg.movement().name(),
cfg.animation_frames(),
backend::hold(&cfg).as_millis(),
cfg.fade().as_millis(),
colors.join(" "),
);
let mut blinks: u64 = 0;
loop {
if let Err(e) = backend.blink(&cfg) {
eprintln!("blink error: {e}");
}
blinks += 1;
if count.is_some_and(|n| blinks >= n) {
break;
}
thread::sleep(Duration::from_secs(cfg.sleep_secs()));
}
Ok(())
}