|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
use std::time::{Duration, SystemTime};
|
|
|
|
|
use std::io::Write;
|
|
|
|
|
use std::net::TcpStream;
|
|
|
|
|
use eframe::egui;
|
|
|
|
|
use egui::FontFamily::Proportional;
|
|
|
|
@ -24,7 +23,9 @@ pub struct App {
|
|
|
|
|
pub irc_connected: bool,
|
|
|
|
|
pub show_market_data: bool,
|
|
|
|
|
pub show_radio: bool,
|
|
|
|
|
pub irc_stream: Result<TcpStream, std::io::Error>,
|
|
|
|
|
pub irc_stream: Option<TcpStream>,
|
|
|
|
|
pub irc_last_ping: SystemTime,
|
|
|
|
|
pub irc_active_channel: String
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for App {
|
|
|
|
@ -42,7 +43,9 @@ impl Default for App {
|
|
|
|
|
to_data: "".to_owned(),
|
|
|
|
|
irc_message: "".to_owned(),
|
|
|
|
|
show_radio: true,
|
|
|
|
|
irc_stream: TcpStream::connect("0.0.0.0:0")
|
|
|
|
|
irc_stream: None,
|
|
|
|
|
irc_last_ping: SystemTime::now(),
|
|
|
|
|
irc_active_channel: "#wownero-music".to_owned()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -79,8 +82,8 @@ impl eframe::App for App {
|
|
|
|
|
if (self.tor_connected && self.tor_required) || (! self.tor_required) {
|
|
|
|
|
ui.checkbox(&mut self.show_market_data, "Show Market Data");
|
|
|
|
|
ui.checkbox(&mut self.show_irc, "Show IRC");
|
|
|
|
|
ui.checkbox(&mut self.show_radio, "Show Radio");
|
|
|
|
|
}
|
|
|
|
|
ui.checkbox(&mut self.show_radio, "Show Radio");
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
// Tor
|
|
|
|
@ -119,7 +122,6 @@ impl eframe::App for App {
|
|
|
|
|
ui.add(egui::Slider::new(&mut self.player.volume, 0.0..=100.0));
|
|
|
|
|
self.player.sink.set_volume(self.player.volume / 100.0);
|
|
|
|
|
if self.player.sink.len() != 1 {
|
|
|
|
|
// let _ = self.player.wait_for_source();
|
|
|
|
|
let f = std::fs::File::open(crate::RADIO_STREAM);
|
|
|
|
|
if let Ok(fo) = f {
|
|
|
|
|
let file = std::io::BufReader::new(fo);
|
|
|
|
@ -127,7 +129,6 @@ impl eframe::App for App {
|
|
|
|
|
if source.is_err() {
|
|
|
|
|
return ()
|
|
|
|
|
}
|
|
|
|
|
// let _ = self.player.sink.stop();
|
|
|
|
|
let _ = self.player.sink.append(source.unwrap());
|
|
|
|
|
let _ = self.player.sink.play();
|
|
|
|
|
} else {
|
|
|
|
@ -190,17 +191,30 @@ impl eframe::App for App {
|
|
|
|
|
|
|
|
|
|
// IRC
|
|
|
|
|
if self.show_irc && ! self.irc_connected {
|
|
|
|
|
self.irc_stream = self.irc.run();
|
|
|
|
|
self.irc_connected = true;
|
|
|
|
|
let i = self.irc.run();
|
|
|
|
|
if i.is_ok() {
|
|
|
|
|
self.irc_stream = Some(i.unwrap());
|
|
|
|
|
self.irc_connected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else if self.show_irc {
|
|
|
|
|
egui::ScrollArea::vertical().stick_to_bottom(true).show(ui, |ui| {
|
|
|
|
|
ui.label(self.irc.read_irc_log());
|
|
|
|
|
ui.label(self.irc.read_irc_log(self.irc_active_channel.clone()));
|
|
|
|
|
ui.horizontal(|ui| {
|
|
|
|
|
egui::ComboBox::from_label("")
|
|
|
|
|
.selected_text(format!("{}", self.irc_active_channel))
|
|
|
|
|
.show_ui(ui, |ui| {
|
|
|
|
|
ui.selectable_value(&mut self.irc_active_channel, "".to_owned(), "system");
|
|
|
|
|
ui.selectable_value(&mut self.irc_active_channel, "#wownero-music".to_owned(), "#wownero-music");
|
|
|
|
|
ui.selectable_value(&mut self.irc_active_channel, "#wownero".to_owned(), "#wownero");
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
ui.text_edit_singleline(&mut self.irc_message);
|
|
|
|
|
if ui.button("> Send <").clicked() {
|
|
|
|
|
let res = self.irc_stream.as_ref().unwrap().write(self.irc_message.as_bytes());
|
|
|
|
|
let res = crate::irc::send_cmd(&self.irc_stream.as_ref().unwrap(), "PRIVMSG", format!("{} :{}\r\n", self.irc_active_channel, self.irc_message));
|
|
|
|
|
if res.is_ok() {
|
|
|
|
|
println!("wrote {} bytes to IRC: {}", res.unwrap(), self.irc_message);
|
|
|
|
|
let _ = crate::irc::write_log(format!("PRIVMSG {} :{}\r\n", self.irc_active_channel, self.irc_message).as_str(), false);
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("error: {:?}", res.err());
|
|
|
|
|
}
|
|
|
|
@ -210,6 +224,10 @@ impl eframe::App for App {
|
|
|
|
|
if ui.button("Clear IRC Log").clicked() {
|
|
|
|
|
let _ = std::fs::File::create(crate::IRC_LOG);
|
|
|
|
|
}
|
|
|
|
|
if self.irc_last_ping.elapsed().unwrap() > Duration::from_secs(60) {
|
|
|
|
|
let _ = crate::irc::send_cmd(&self.irc_stream.as_ref().unwrap(), "PING", format!(""));
|
|
|
|
|
self.irc_last_ping = SystemTime::now();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|