Skip to main content

flashkraft_gui/
lib.rs

1//! FlashKraft GUI Library
2//!
3//! This crate contains the Iced desktop application for FlashKraft.
4//!
5//! ## Contents
6//!
7//! | Module | What lives here |
8//! |--------|-----------------|
9//! | [`core`] | Iced app state, messages, update logic, flash subscription, storage |
10//! | [`components`] | Iced UI widgets and component renderers |
11//! | [`view`] | Top-level view orchestration |
12//! | [`utils`] | GUI-specific utilities (Bootstrap icon mapper) |
13//!
14//! ## Dependency on `flashkraft-core`
15//!
16//! All domain models, the flash pipeline, and drive-detection logic live in
17//! the `flashkraft-core` crate.  This crate re-exports the most commonly
18//! used types so callers only need to import from `flashkraft_gui`.
19
20// GUI-specific utilities (Bootstrap icon mapper uses iced types)
21#[macro_use]
22pub mod utils;
23
24pub mod components;
25pub mod core;
26pub mod view;
27
28// ── Core re-exports ───────────────────────────────────────────────────────────
29
30// Re-export `flashkraft_core::domain` at the crate root so that submodules can
31// use `crate::domain::DriveInfo` / `crate::domain::ImageInfo` etc.
32pub use flashkraft_core::domain;
33
34// Re-export the `flash_debug!` macro from flashkraft_core so that
35// `use crate::flash_debug;` in flash_subscription.rs resolves correctly.
36pub use flashkraft_core::debug_log;
37pub use flashkraft_core::flash_debug;
38pub use flashkraft_core::status_log;
39
40// Re-export Iced app entry points
41pub use core::{FlashKraft, Message};
42
43// ── GUI entry point ───────────────────────────────────────────────────────────
44
45/// Entry point for the Iced desktop GUI.
46///
47/// The binary must be installed **setuid-root** for the flash pipeline to be
48/// able to open block devices:
49///
50/// ```text
51/// sudo chown root:root /usr/bin/flashkraft
52/// sudo chmod u+s       /usr/bin/flashkraft
53/// ```
54///
55/// The real UID is captured in `main.rs` before this function is called.
56pub fn run_gui() -> iced::Result {
57    use iced::{Settings, Task};
58
59    iced::application(
60        "FlashKraft - OS Image Writer",
61        FlashKraft::update,
62        FlashKraft::view,
63    )
64    .subscription(FlashKraft::subscription)
65    .theme(|state: &FlashKraft| state.theme.clone())
66    .settings(Settings {
67        fonts: vec![iced_fonts::BOOTSTRAP_FONT_BYTES.into()],
68        ..Default::default()
69    })
70    .window(iced::window::Settings {
71        size: iced::Size::new(1300.0, 700.0),
72        resizable: false,
73        decorations: true,
74        ..Default::default()
75    })
76    .run_with(|| {
77        let initial_state = FlashKraft::new();
78        let initial_command = Task::perform(
79            flashkraft_core::commands::load_drives(),
80            Message::DrivesRefreshed,
81        );
82        (initial_state, initial_command)
83    })
84}
85
86// Re-export domain types from core so downstream code can do
87// `use flashkraft_gui::{DriveInfo, ImageInfo}` without knowing about
88// flashkraft-core directly.
89pub use flashkraft_core::{DriveInfo, ImageInfo};