generated from lks/eframe_template_android
Add close fn to device trait
This commit is contained in:
parent
d1271c1f7d
commit
edcf10f73c
11
src/app.rs
11
src/app.rs
@ -84,6 +84,13 @@ impl eframe::App for TemplateApp {
|
|||||||
if ui.button("Open Device").clicked() {
|
if ui.button("Open Device").clicked() {
|
||||||
self.device_window_open = true;
|
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 !is_web {
|
||||||
if ui.button("Quit").clicked() {
|
if ui.button("Quit").clicked() {
|
||||||
ctx.send_viewport_cmd(egui::ViewportCommand::Close);
|
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];
|
//let mut b = &self._backends.0[self._selected_backend];
|
||||||
b.show_device_selection(ui);
|
b.show_device_selection(ui);
|
||||||
if ui.add(egui::Button::new("Apply")).clicked() {
|
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) =
|
if let Ok(device) =
|
||||||
b.build_device(self.fft.tx.clone(), self.plots.get_sender())
|
b.build_device(self.fft.tx.clone(), self.plots.get_sender())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -48,6 +48,10 @@ impl crate::backend::Device for Audio {
|
|||||||
fn tune(&mut self, _freq: usize) -> anyhow::Result<()> {
|
fn tune(&mut self, _freq: usize) -> anyhow::Result<()> {
|
||||||
anyhow::bail!("Can't tune this device")
|
anyhow::bail!("Can't tune this device")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn close(self: Box<Self>) {
|
||||||
|
drop(self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AudioBackend {
|
pub struct AudioBackend {
|
||||||
|
|||||||
@ -8,6 +8,7 @@ pub trait Device {
|
|||||||
fn show_settings(&mut self, ui: &mut Ui);
|
fn show_settings(&mut self, ui: &mut Ui);
|
||||||
fn can_tune(&self) -> bool;
|
fn can_tune(&self) -> bool;
|
||||||
fn tune(&mut self, freq: usize) -> anyhow::Result<()>;
|
fn tune(&mut self, freq: usize) -> anyhow::Result<()>;
|
||||||
|
fn close(self: Box<Self>);
|
||||||
}
|
}
|
||||||
pub trait Backend {
|
pub trait Backend {
|
||||||
fn display_text(&self) -> &'static str;
|
fn display_text(&self) -> &'static str;
|
||||||
@ -29,14 +30,10 @@ impl Default for Backends {
|
|||||||
|
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
impl Default for Backends {
|
impl Default for Backends {
|
||||||
fn default() -> Self {
|
fn default() -> Self {}
|
||||||
Backends(vec![])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
impl Default for Backends {
|
impl Default for Backends {
|
||||||
fn default() -> Self {
|
fn default() -> Self {}
|
||||||
Backends(vec![])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user