purger_gui/
lib.rs

1use anyhow::Result;
2use eframe::egui;
3
4mod app;
5mod handlers;
6mod simple_i18n;
7mod state;
8mod ui;
9
10use app::PurgerApp;
11use simple_i18n::translate;
12
13pub fn run_gui() -> Result<()> {
14    // Logging is initialized by the caller binary or by the GUI-only binary.
15    // If it is already initialized, this will return an error, so we use `try_init`.
16    let _ = tracing_subscriber::fmt()
17        .with_max_level(tracing::Level::INFO)
18        .try_init();
19
20    let options = eframe::NativeOptions {
21        viewport: egui::ViewportBuilder::default()
22            .with_inner_size([800.0, 600.0])
23            .with_min_inner_size([600.0, 400.0]),
24        ..Default::default()
25    };
26
27    eframe::run_native(
28        &translate("app.title"),
29        options,
30        Box::new(|cc| {
31            setup_custom_fonts(&cc.egui_ctx);
32            let app = PurgerApp::new(cc);
33            Ok(Box::new(app))
34        }),
35    )
36    .map_err(|e| anyhow::anyhow!("Failed to run GUI: {}", e))
37}
38
39fn setup_custom_fonts(ctx: &egui::Context) {
40    let mut fonts = egui::FontDefinitions::default();
41
42    fonts.font_data.insert(
43        "noto_sans_sc".to_owned(),
44        egui::FontData::from_static(include_bytes!("../assets/NotoSansSC-Regular.ttf")).into(),
45    );
46
47    fonts
48        .families
49        .entry(egui::FontFamily::Proportional)
50        .or_default()
51        .insert(0, "noto_sans_sc".to_owned());
52
53    fonts
54        .families
55        .entry(egui::FontFamily::Monospace)
56        .or_default()
57        .insert(0, "noto_sans_sc".to_owned());
58
59    ctx.set_fonts(fonts);
60}