#![allow(internal_features)] #![feature(core_intrinsics)] use std::{ffi::c_char, process::ExitCode, time::Duration}; use clap::Parser; mod display; mod plugman; mod config; mod util; #[derive(Debug, Parser)] struct CliArgs { #[arg(long, short, default_value="./plugins")] pub plugin_dir: camino::Utf8PathBuf, #[arg(long, short, default_value="./config")] pub config_dir: camino::Utf8PathBuf, #[arg(long, short)] pub debug: bool } #[allow(non_camel_case_types)] pub type c_str = *const c_char; // TODO: Clean up main function // TODO: Make ffi safe abstraction for logger // TODO: Set up ipc with unix sockets // TODO: Allow sending messages command -> running DIM instance -> plugin with ipc // TODO: Run code through clippy fn main() -> ExitCode { let ca = CliArgs::parse(); if ca.debug { env_logger::builder() .filter(None, log::LevelFilter::Debug) .init(); } else { env_logger::builder() .filter(None, log::LevelFilter::Info) .init(); } let config; match config::Config::new(ca.config_dir.as_std_path()) { Ok(v) => config = v, Err(e) => { log::error!("Failed to parse config: {e:?}"); return ExitCode::from(2); } }; let Ok(mut disp) = display::Display::new() else { return ExitCode::from(1); }; let mut pm = plugman::PlugMan::new(1024); // idk tbh if let Err(e) = pm.load(ca.plugin_dir.as_std_path().to_path_buf()){ log::error!("Failed to load plugins: {e:?}"); return ExitCode::from(3); } pm.init_plugins(&config); loop { let vals = pm.poll_plugins(); if let Err(e) = disp.write_with_vec(&config, vals) { log::warn!("Failed to write too bar: {e}"); } std::thread::sleep(Duration::from_millis(250)); } }