You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
153 lines
6.3 KiB
153 lines
6.3 KiB
use std::time::{Duration, SystemTime};
|
|
use eframe::egui;
|
|
use egui::FontFamily::Proportional;
|
|
use egui::FontId;
|
|
use egui::TextStyle::*;
|
|
use crate::player::Player;
|
|
use libtor::Error as libtorError;
|
|
|
|
pub struct App {
|
|
pub player: Player,
|
|
pub tor_started: bool,
|
|
pub tor_connected: bool,
|
|
pub to_data: String,
|
|
pub show_irc: bool,
|
|
pub irc_message: String
|
|
}
|
|
|
|
impl Default for App {
|
|
fn default() -> Self {
|
|
Self {
|
|
tor_started: false,
|
|
tor_connected: false,
|
|
show_irc: false,
|
|
to_data: "".to_owned(),
|
|
player: Player::default(),
|
|
irc_message: "".to_owned()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for App {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
let mut style = (*ctx.style()).clone();
|
|
style.text_styles = [
|
|
(Heading, FontId::new(30.0, Proportional)),
|
|
(Name("Heading2".into()), FontId::new(25.0, Proportional)),
|
|
(Name("Context".into()), FontId::new(23.0, Proportional)),
|
|
(Body, FontId::new(18.0, Proportional)),
|
|
(Monospace, FontId::new(14.0, Proportional)),
|
|
(Button, FontId::new(14.0, Proportional)),
|
|
(Small, FontId::new(10.0, Proportional)),
|
|
].into();
|
|
ctx.set_style(style);
|
|
ctx.set_visuals(egui::Visuals::dark());
|
|
|
|
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
|
ui.heading("Wownero Operations Center");
|
|
ui.label("Made by ya boi, lza_menace");
|
|
ui.hyperlink("https://lzahq.tech");
|
|
});
|
|
|
|
// Show volume controls
|
|
if self.tor_connected {
|
|
egui::TopBottomPanel::bottom("radio_player").show(ctx, |ui| {
|
|
ui.heading(egui::RichText::new("WOW!Radio").color(egui::Color32::GREEN));
|
|
ui.label(egui::RichText::new("Your home for the most diabolical playlist of the century, made by the skeevers, scallywags, chupacabras, and whores of the Wownero community. Join da chat to peep da scoop.\n").color(egui::Color32::GREEN));
|
|
ui.horizontal(|ui| {
|
|
if self.player.playing {
|
|
if ui.button("⏸").clicked() {
|
|
let _ = &self.player.sink.pause();
|
|
self.player.playing = false;
|
|
}
|
|
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);
|
|
let source = rodio::Decoder::new(file);
|
|
if source.is_err() {
|
|
return ()
|
|
}
|
|
// let _ = self.player.sink.stop();
|
|
let _ = self.player.sink.append(source.unwrap());
|
|
let _ = self.player.sink.play();
|
|
} else {
|
|
return ()
|
|
}
|
|
}
|
|
} else {
|
|
if ui.button("▶").clicked() {
|
|
// If stream thread is done, start again
|
|
if self.player.stream_thread.is_finished() {
|
|
self.player.stream_thread = self.player.start_radio_stream();
|
|
}
|
|
let _ = self.player.sink.play();
|
|
self.player.playing = true;
|
|
}
|
|
|
|
}
|
|
});
|
|
|
|
// Show spinner when downloading, along with file size
|
|
if ! self.player.stream_thread.is_finished() {
|
|
ui.horizontal(|ui| {
|
|
ui.spinner();
|
|
let size: u64 = self.player.get_radio_size();
|
|
ui.label(format!(
|
|
"{:?} -> {} ({} bytes)",
|
|
self.player.stream_source,
|
|
crate::RADIO_STREAM,
|
|
size
|
|
));
|
|
});
|
|
}
|
|
|
|
// Show exif metadata when radio file available to read
|
|
if self.player.playing && self.player.get_radio_size() > 0 {
|
|
let rt = egui::RichText::new(
|
|
format!("\n{:?}", self.player.stream_exif))
|
|
.color(egui::Color32::WHITE)
|
|
.size(18.0);
|
|
ui.label(rt);
|
|
let dur = self.player.exif_date.elapsed().unwrap();
|
|
if dur > Duration::from_secs(8) {
|
|
self.player.exif_date = SystemTime::now();
|
|
self.player.stream_exif = self.player.get_song_meta().unwrap();
|
|
}
|
|
}
|
|
ui.label("");
|
|
});
|
|
}
|
|
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
if self.tor_started {
|
|
ui.label("Tor started.");
|
|
if ui.button("Clear Tor logs").clicked() {
|
|
let _r: std::io::Result<()> = crate::clear_tor_log();
|
|
}
|
|
if ui.button("Check Proxy").clicked() {
|
|
if self.player.check_proxy() {
|
|
self.tor_connected = true;
|
|
}
|
|
}
|
|
ui.collapsing("View Tor logs:", |ui| {
|
|
egui::ScrollArea::vertical().stick_to_bottom(true).show(ui, |ui| {
|
|
let contents = std::fs::read_to_string(crate::TOR_LOG.to_string()).unwrap();
|
|
ui.label(contents);
|
|
});
|
|
});
|
|
} else {
|
|
if ui.button("Enter the WOW!Verse").clicked() {
|
|
let _t: std::thread::JoinHandle<Result<u8, libtorError>> = crate::start_tor();
|
|
self.tor_started = true;
|
|
self.tor_connected = true;
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
}
|
|
} |