use eframe::egui;
mod agent_tools;
pub mod app;
pub mod headless;
mod profile_tab;
mod system_summary;
mod theme;
pub mod widgets;
pub use app::IronMonitorApp;
#[cfg(windows)]
fn screen_size() -> Option<egui::Vec2> {
unsafe {
const SM_CXSCREEN: i32 = 0;
const SM_CYSCREEN: i32 = 1;
unsafe extern "system" {
fn GetSystemMetrics(index: i32) -> i32;
}
let (w, h) = (GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN));
(w > 0 && h > 0).then(|| egui::vec2(w as f32, h as f32))
}
}
#[cfg(not(windows))]
fn screen_size() -> Option<egui::Vec2> {
None
}
pub fn run() -> Result<(), eframe::Error> {
const PREFERRED_WIDTH: f32 = 1400.0;
const PREFERRED_HEIGHT: f32 = 900.0;
let preferred = egui::vec2(PREFERRED_WIDTH, PREFERRED_HEIGHT);
let size = match screen_size() {
Some(screen) => preferred.min(screen * 0.92),
None => preferred,
};
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_inner_size([size.x, size.y])
.with_min_inner_size([800.0_f32.min(size.x), 600.0_f32.min(size.y)])
.with_title("IronMonitor")
.with_icon(load_icon()),
hardware_acceleration: eframe::HardwareAcceleration::Preferred,
vsync: true,
..Default::default()
};
eframe::run_native(
"IronMonitor",
options,
Box::new(|cc| Ok(Box::new(IronMonitorApp::new(cc)))),
)
}
fn load_icon() -> egui::IconData {
let size = 32;
let mut rgba = vec![0u8; size * size * 4];
for y in 0..size {
for x in 0..size {
let idx = (y * size + x) * 4;
let in_border = x < 2 || x >= size - 2 || y < 2 || y >= size - 2;
let in_s = (y < size / 3 && (x > size / 4 || y < 4))
|| (y >= size / 3 && y < 2 * size / 3 && x > size / 4 && x < 3 * size / 4)
|| (y >= 2 * size / 3 && (x < 3 * size / 4 || y >= size - 4));
if in_border || in_s {
rgba[idx] = 0; rgba[idx + 1] = 255; rgba[idx + 2] = 255; rgba[idx + 3] = 255; }
}
}
egui::IconData {
rgba,
width: size as u32,
height: size as u32,
}
}