diff --git a/src/app.rs b/src/app.rs index 459f739..da13ac4 100644 --- a/src/app.rs +++ b/src/app.rs @@ -84,6 +84,13 @@ impl eframe::App for TemplateApp { if ui.button("Open Device").clicked() { self.device_window_open = true; } + if self.open_device.is_some() { + if ui.button("Close Device").clicked() { + if let Some(dev) = self.open_device.take() { + dev.close(); + } + } + } if !is_web { if ui.button("Quit").clicked() { ctx.send_viewport_cmd(egui::ViewportCommand::Close); @@ -185,7 +192,9 @@ impl eframe::App for TemplateApp { //let mut b = &self._backends.0[self._selected_backend]; b.show_device_selection(ui); if ui.add(egui::Button::new("Apply")).clicked() { - drop(self.open_device.take()); + if let Some(dev) = self.open_device.take() { + dev.close() + }; if let Ok(device) = b.build_device(self.fft.tx.clone(), self.plots.get_sender()) { diff --git a/src/backend/audio.rs b/src/backend/audio.rs index 9dda17b..de17cbb 100644 --- a/src/backend/audio.rs +++ b/src/backend/audio.rs @@ -48,6 +48,10 @@ impl crate::backend::Device for Audio { fn tune(&mut self, _freq: usize) -> anyhow::Result<()> { anyhow::bail!("Can't tune this device") } + + fn close(self: Box) { + drop(self); + } } pub struct AudioBackend { diff --git a/src/backend/mod.rs b/src/backend/mod.rs index 9ee766c..345be17 100644 --- a/src/backend/mod.rs +++ b/src/backend/mod.rs @@ -8,6 +8,7 @@ pub trait Device { fn show_settings(&mut self, ui: &mut Ui); fn can_tune(&self) -> bool; fn tune(&mut self, freq: usize) -> anyhow::Result<()>; + fn close(self: Box); } pub trait Backend { fn display_text(&self) -> &'static str; @@ -29,14 +30,10 @@ impl Default for Backends { #[cfg(target_arch = "wasm32")] impl Default for Backends { - fn default() -> Self { - Backends(vec![]) - } + fn default() -> Self {} } #[cfg(target_os = "android")] impl Default for Backends { - fn default() -> Self { - Backends(vec![]) - } + fn default() -> Self {} }