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::flash_debug;
37
38// Re-export Iced app entry points
39pub use core::{FlashKraft, Message};
40
41// ── GUI entry point ───────────────────────────────────────────────────────────
42
43/// Entry point for the Iced desktop GUI.
44///
45/// The binary must be installed **setuid-root** for the flash pipeline to be
46/// able to open block devices:
47///
48/// ```text
49/// sudo chown root:root /usr/bin/flashkraft
50/// sudo chmod u+s /usr/bin/flashkraft
51/// ```
52///
53/// The real UID is captured in `main.rs` before this function is called.
54pub fn run_gui() -> iced::Result {
55 use iced::{Settings, Task};
56
57 iced::application(
58 "FlashKraft - OS Image Writer",
59 FlashKraft::update,
60 FlashKraft::view,
61 )
62 .subscription(FlashKraft::subscription)
63 .theme(|state: &FlashKraft| state.theme.clone())
64 .settings(Settings {
65 fonts: vec![iced_fonts::BOOTSTRAP_FONT_BYTES.into()],
66 ..Default::default()
67 })
68 .window(iced::window::Settings {
69 size: iced::Size::new(1300.0, 700.0),
70 resizable: false,
71 decorations: true,
72 ..Default::default()
73 })
74 .run_with(|| {
75 let initial_state = FlashKraft::new();
76 let initial_command = Task::perform(
77 flashkraft_core::commands::load_drives(),
78 Message::DrivesRefreshed,
79 );
80 (initial_state, initial_command)
81 })
82}
83
84// Re-export domain types from core so downstream code can do
85// `use flashkraft_gui::{DriveInfo, ImageInfo}` without knowing about
86// flashkraft-core directly.
87pub use flashkraft_core::{DriveInfo, ImageInfo};