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 Flash but the process is not privileged — attempt to
47 /// re-exec via pkexec / sudo so the user gets a password prompt, then
48 /// restart the app with the same selections intact.
49 EscalateAndFlash,
50
51 /// User clicked the "Reset" button (start over)
52 ResetClicked,
53
54 /// User clicked the "Cancel" button
55 CancelClicked,
56
57 /// User clicked "Cancel" during flash operation
58 CancelFlash,
59
60 // ========================================================================
61 // Animation Messages
62 // ========================================================================
63 /// Animation tick for progress bar effects
64 AnimationTick,
65
66 // ========================================================================
67 // Async Result Messages
68 // ========================================================================
69 /// Result from async image file selection
70 ///
71 /// Contains `Some(path)` if user selected a file, `None` if cancelled
72 ImageSelected(Option<PathBuf>),
73
74 /// Result from async drive detection
75 ///
76 /// Contains a list of detected drives
77 DrivesRefreshed(Vec<DriveInfo>),
78
79 /// Progress update from flash subscription
80 ///
81 /// Contains (progress 0.0-1.0, bytes_written, speed_mb_per_sec)
82 FlashProgressUpdate(f32, u64, f32),
83
84 /// Verification read-back progress update.
85 ///
86 /// Contains (overall 0.0–1.0 across both passes, phase, bytes_read, total_bytes, speed_mb_s)
87 VerifyProgressUpdate(f32, &'static str, u64, u64, f32),
88
89 /// Status message from flash operation
90 Status(String),
91
92 /// Result from async flash operation
93 ///
94 /// Contains `Ok(())` on success or `Err(message)` on failure
95 FlashCompleted(Result<(), String>),
96
97 /// User changed the application theme
98 ThemeChanged(Theme),
99}