diff --git a/src/ui/main_window.rs b/src/ui/main_window.rs index 33e078a..47ba0d5 100644 --- a/src/ui/main_window.rs +++ b/src/ui/main_window.rs @@ -56,6 +56,19 @@ impl MainWindow { return Task::none(); } iced::window::Event::CloseRequested => { + // Suppress the close while an operation is in progress + // so OpenOCD (or the FUS upgrade) isn't interrupted + // mid-action. The opacity overlay already signals the + // busy state visually; the user can force-quit / end + // task the app if they really need out, but a misclick + // on the X shouldn't brick the device. + if self.tab_daplink.is_busy() || self.tab_ws.is_busy() { + eprintln!( + "Close request ignored: an operation is in progress." + ); + return Task::none(); + } + match dirs::get_settings_dir() { Ok(settings_dir) => { let fields_file = settings_dir.join(SETTINGS_FILE); diff --git a/src/ui/tab_daplink.rs b/src/ui/tab_daplink.rs index c630117..8b703bf 100644 --- a/src/ui/tab_daplink.rs +++ b/src/ui/tab_daplink.rs @@ -38,6 +38,14 @@ pub struct TabDaplink { } impl TabDaplink { + /// True while an operation that should not be interrupted is running: + /// a flash sequence, or a (modal) file-browse. Used by `MainWindow` to + /// suppress window-close requests so the OpenOCD child isn't killed + /// mid-write. + pub fn is_busy(&self) -> bool { + self.is_readonly + } + pub fn update(&mut self, message: TabDaplinkMessage) -> Task { match message { TabDaplinkMessage::LogMessage(log) => self.log_widget.push(log), diff --git a/src/ui/tab_wireless_stack.rs b/src/ui/tab_wireless_stack.rs index 42bccf6..62fd210 100644 --- a/src/ui/tab_wireless_stack.rs +++ b/src/ui/tab_wireless_stack.rs @@ -103,6 +103,13 @@ const ALL_STACK: [WirelessStackFile; 21] = [ ]; impl TabWirelessStack { + /// True while an operation that should not be interrupted is running. + /// Used by `MainWindow` to suppress window-close requests so neither + /// the OpenOCD child nor an in-flight FUS upgrade gets cut mid-action. + pub fn is_busy(&self) -> bool { + self.is_readonly + } + pub fn view(&self) -> Element { let grid_fields = grid!( grid_row!(