Add close fn to device trait

This commit is contained in:
Lucas Schumacher 2024-06-19 09:24:20 -04:00
parent d1271c1f7d
commit edcf10f73c
3 changed files with 17 additions and 7 deletions

View File

@ -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())
{

View File

@ -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<Self>) {
drop(self);
}
}
pub struct AudioBackend {

View File

@ -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<Self>);
}
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 {}
}