Gui cleanup

This commit is contained in:
joeyahines committed 2026-10-16 19:27:04 -06:00
1 parent 1ab9260a39
commit ce112f31a1
2 files changed
+27 -6

No files matched your search

+1
View File
@@ -138,6 +138,7 @@ impl AudioSourceThread {
} }
} else { } else {
error!("Channel closing, stopping threads"); error!("Channel closing, stopping threads");
drop(stream);
drop(sender); drop(sender);
thread.join().unwrap(); thread.join().unwrap();
return Ok(()); return Ok(());
+26 -6
View File
@@ -2,7 +2,7 @@ use cpal::traits::{DeviceTrait, HostTrait};
use eframe::{App, Frame}; use eframe::{App, Frame};
use egui::Ui; use egui::Ui;
use env_logger::Env; use env_logger::Env;
use log::{error, info}; use log::error;
use std::sync::mpsc::{Receiver, channel}; use std::sync::mpsc::{Receiver, channel};
use std::thread; use std::thread;
use std::thread::JoinHandle; use std::thread::JoinHandle;
@@ -36,12 +36,18 @@ pub struct Tap {
host: cpal::Host, host: cpal::Host,
} }
impl Default for Tap {
fn default() -> Self {
Self::new()
}
}
impl Tap { impl Tap {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
mode: Default::default(), mode: Default::default(),
device: "".to_string(), device: "".to_string(),
denny_jack_host: "".to_string(), denny_jack_host: "158.69.121.46:9999".to_string(),
warning: "".to_string(), warning: "".to_string(),
join_handle: None, join_handle: None,
channel: None, channel: None,
@@ -73,12 +79,17 @@ impl Tap {
} }
impl App for Tap { impl App for Tap {
fn ui(&mut self, ui: &mut Ui, frame: &mut Frame) { fn ui(&mut self, ui: &mut Ui, _frame: &mut Frame) {
let panel_frame = egui::containers::CentralPanel::default_margins();
panel_frame.show(ui, |ui| {
ui.heading("Tap GUI");
ui.add_space(4.0);
match self.mode { match self.mode {
State::Init => { State::Init => {
ui.label("Denny Jack Host"); ui.label("Denny Jack Host");
ui.text_edit_singleline(&mut self.denny_jack_host); ui.text_edit_singleline(&mut self.denny_jack_host);
egui::containers::ComboBox::from_label("Device:") egui::containers::ComboBox::from_label("Device")
.selected_text(&self.device) .selected_text(&self.device)
.show_ui(ui, |ui| { .show_ui(ui, |ui| {
for device in self.host.devices().unwrap() { for device in self.host.devices().unwrap() {
@@ -100,7 +111,7 @@ impl App for Tap {
} }
if !self.warning.is_empty() { if !self.warning.is_empty() {
ui.label(format!("Error: {}", &self.warning)); ui.label(format!("Error: {}", self.warning));
} }
} }
State::Connecting => { State::Connecting => {
@@ -130,9 +141,18 @@ impl App for Tap {
self.join_handle = None; self.join_handle = None;
self.mode = State::Init; self.mode = State::Init;
} }
if ui.button("Disconnect").clicked() {
self.channel = None;
let handle = self.join_handle.take().unwrap();
let _ = handle.join();
self.join_handle = None;
self.mode = State::Init;
} }
} }
} }
});
}
} }
#[tokio::main] #[tokio::main]
@@ -142,5 +162,5 @@ async fn main() -> Result<(), eframe::Error> {
..Default::default() ..Default::default()
}; };
eframe::run_native("Tap", options, Box::new(|cc| Ok(Box::new(Tap::new())))) eframe::run_native("Tap", options, Box::new(|_cc| Ok(Box::new(Tap::new()))))
} }