diff --git a/src/lib.rs b/src/lib.rs index 39f1f1d1..00efe19c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -243,9 +243,8 @@ pub async fn run(args: Args, arg_count: usize) -> std::io::Result<()> { } } } - if let Some(shutdown_tx) = &shutdown_tx { - ui::usb::close(shutdown_tx, usb_handle).await; - } + + ui::usb::close(shutdown_tx, usb_handle).await; } else if arg_count > 1 { let mut config = ui::config::Config::new(); diff --git a/src/ui/usb.rs b/src/ui/usb.rs index 9546935b..6cf5843a 100644 --- a/src/ui/usb.rs +++ b/src/ui/usb.rs @@ -175,16 +175,19 @@ pub fn init() -> ( } pub async fn close( - shutdown_tx: &tokio::sync::watch::Sender<()>, + shutdown_tx: Option>, usb_handle: Option>, ) { - let _ = shutdown_tx.send(()); if let Some(mut handle) = usb_handle - && tokio::time::timeout(std::time::Duration::from_secs(1), &mut handle) + && let Some(shutdown_tx) = shutdown_tx + { + let _ = shutdown_tx.send(()); + if tokio::time::timeout(std::time::Duration::from_secs(1), &mut handle) .await .is_err() - { - handle.abort(); + { + handle.abort(); + } } }