Skip to main content

flashkraft_gui/core/
message.rs

1//! Message - Events in The Elm Architecture
2//!
3//! This module defines all possible messages (events) that can occur
4//! in the FlashKraft application. Messages are the only way to trigger
5//! state changes, making the application predictable and debuggable.
6
7use std::path::PathBuf;
8
9use crate::domain::DriveInfo;
10use iced::Theme;
11
12/// All possible messages in the application
13///
14/// Messages represent events that can occur, either from user interactions
15/// or as results of asynchronous operations (Commands).
16#[derive(Debug, Clone)]
17pub enum Message {
18    // ========================================================================
19    // User Interaction Messages
20    // ========================================================================
21    /// User clicked the "Select Image" button
22    SelectImageClicked,
23
24    /// User clicked the "Refresh Drives" button
25    RefreshDrivesClicked,
26
27    /// A USB device was connected or disconnected — triggers re-enumeration.
28    ///
29    /// Emitted by the hotplug subscription in [`crate::core::state`] and
30    /// handled by immediately re-running drive detection, exactly as if the
31    /// user had pressed Refresh.
32    UsbHotplugDetected,
33
34    /// User clicked on a specific target drive
35    TargetDriveClicked(DriveInfo),
36
37    /// User clicked to open the device selection view
38    OpenDeviceSelection,
39
40    /// User clicked to close the device selection view
41    CloseDeviceSelection,
42
43    /// User clicked the "Flash" button
44    FlashClicked,
45
46    /// User clicked the "Reset" button (start over)
47    ResetClicked,
48
49    /// User clicked the "Cancel" button
50    CancelClicked,
51
52    /// User clicked "Cancel" during flash operation
53    CancelFlash,
54
55    // ========================================================================
56    // Animation Messages
57    // ========================================================================
58    /// Animation tick for progress bar effects
59    AnimationTick,
60
61    // ========================================================================
62    // Async Result Messages
63    // ========================================================================
64    /// Result from async image file selection
65    ///
66    /// Contains `Some(path)` if user selected a file, `None` if cancelled
67    ImageSelected(Option<PathBuf>),
68
69    /// Result from async drive detection
70    ///
71    /// Contains a list of detected drives
72    DrivesRefreshed(Vec<DriveInfo>),
73
74    /// Progress update from flash subscription
75    ///
76    /// Contains (progress 0.0-1.0, bytes_written, speed_mb_per_sec)
77    FlashProgressUpdate(f32, u64, f32),
78
79    /// Status message from flash operation
80    Status(String),
81
82    /// Result from async flash operation
83    ///
84    /// Contains `Ok(())` on success or `Err(message)` on failure
85    FlashCompleted(Result<(), String>),
86
87    /// User changed the application theme
88    ThemeChanged(Theme),
89}