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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
gui/src/app.rs

216 lines
9.8 KiB

use std::time::{Duration, SystemTime};
2 years ago
use eframe::egui;
use egui::FontFamily::Proportional;
use egui::FontId;
use egui::TextStyle::*;
2 years ago
use crate::player::Player;
use crate::tor::GuiTor;
2 years ago
use crate::stats::Market;
2 years ago
use libtor::Error as libtorError;
2 years ago
pub struct App {
pub player: Player,
2 years ago
pub tor_required: bool,
2 years ago
pub tor_started: bool,
2 years ago
pub tor_connected: bool,
pub to_data: String,
pub show_irc: bool,
2 years ago
pub irc_message: String,
pub show_market_data: bool,
pub market: Market
2 years ago
}
impl Default for App {
fn default() -> Self {
Self {
tor_started: false,
2 years ago
tor_required: true,
2 years ago
tor_connected: false,
2 years ago
show_market_data: false,
2 years ago
show_irc: false,
2 years ago
to_data: "".to_owned(),
2 years ago
player: Player::default(),
2 years ago
market: Market::new(),
2 years ago
irc_message: "".to_owned()
2 years ago
}
}
}
2 years ago
fn show_boolmoji(b: bool) -> String {
if b { return "✔".to_owned() } else { return "☠".to_owned() }
}
2 years ago
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");
2 years ago
ui.label("Made by ya boi, lza_menace");
ui.hyperlink("https://lzahq.tech");
});
2 years ago
2 years ago
egui::CentralPanel::default().show(ctx, |ui| {
2 years ago
ui.horizontal(|ui| {
ui.checkbox(&mut self.tor_required, "Require Tor");
if (self.tor_connected && self.tor_required) || (! self.tor_required) {
ui.checkbox(&mut self.show_market_data, "Show Market Data");
}
});
2 years ago
ui.separator();
if self.tor_required {
if self.tor_started {
2 years ago
ui.label(
egui::RichText::new(
format!(
"Tor Started: {}\nTor Connected: {}\nProxy Up: {}",
show_boolmoji(self.tor_started),
show_boolmoji(self.tor_connected),
show_boolmoji(self.tor_connected)
)
)
);
2 years ago
} else {
if ui.button("Connect to the Tor network").clicked() {
let _t: std::thread::JoinHandle<Result<u8, libtorError>> = GuiTor::start_tor();
2 years ago
self.tor_started = true;
self.tor_connected = true;
}
}
}
2 years ago
if self.show_market_data {
2 years ago
egui::ComboBox::from_label("Pick currency base.")
.selected_text(format!("{}", self.market.denomination))
.show_ui(ui, |ui| {
ui.selectable_value(&mut self.market.denomination, "sats".to_owned(), "sats");
ui.selectable_value(&mut self.market.denomination, "usd".to_owned(), "usd");
ui.selectable_value(&mut self.market.denomination, "eth".to_owned(), "eth");
}
);
2 years ago
if self.market.last_check_time.elapsed().unwrap() > Duration::from_secs(120) {
println!("[+] refreshing WOW market data.");
self.market.last_cg_data = self.market.get_wow_market(self.tor_required);
self.market.last_check_time = SystemTime::now();
}
let m = &self.market.last_cg_data;
let md = &m["market_data"];
ui.horizontal_wrapped(|ui| {
ui.vertical(|ui| {
2 years ago
ui.label("Current Price");
ui.heading(egui::RichText::new(md["current_price"][&self.market.denomination].to_string()).strong());
ui.label("All-Time High");
ui.heading(egui::RichText::new(md["ath"][&self.market.denomination].to_string()).strong());
ui.label("All-Time Low");
ui.heading(egui::RichText::new(md["atl"][&self.market.denomination].to_string()).strong());
ui.label("Total Volume");
ui.heading(egui::RichText::new(md["total_volume"][&self.market.denomination].to_string()).strong());
ui.label("Market Cap");
ui.heading(egui::RichText::new(md["market_cap"][&self.market.denomination].to_string()).strong());
2 years ago
});
ui.vertical(|ui| {
2 years ago
ui.label("PriceChg% (~24hrs)");
ui.heading(egui::RichText::new(md["price_change_percentage_24h_in_currency"][&self.market.denomination].to_string()).strong());
ui.label("PriceChg% (~7d)");
ui.heading(egui::RichText::new(md["price_change_percentage_7d_in_currency"][&self.market.denomination].to_string()).strong());
ui.label("PriceChg% (~14d)");
ui.heading(egui::RichText::new(md["price_change_percentage_14d_in_currency"][&self.market.denomination].to_string()).strong());
ui.label("PriceChg% (~30d)");
ui.heading(egui::RichText::new(md["price_change_percentage_30d_in_currency"][&self.market.denomination].to_string()).strong());
2 years ago
});
});
}
2 years ago
});
// Show volume controls
egui::TopBottomPanel::bottom("radio_player").show(ctx, |ui| {
2 years ago
ui.heading(egui::RichText::new("WOW!Radio").color(egui::Color32::WHITE));
ui.label(egui::RichText::new("Your home for the most diabolical playlist of the century, made by the skeevers, scallywags, chupacabras, snails, and whores of the Wownero community. Join da chat to peep da scoop.\n").color(egui::Color32::WHITE));
2 years ago
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 ()
}
2 years ago
// let _ = self.player.sink.stop();
let _ = self.player.sink.append(source.unwrap());
let _ = self.player.sink.play();
} else {
return ()
}
2 years ago
}
} else {
if ! self.tor_connected && self.tor_required {
ui.label("Connect to the Tor network first.");
2 years ago
} else {
if ui.button("▶").clicked() {
2 years ago
if ! self.tor_connected && self.tor_required {
return ();
}
2 years ago
// If stream thread is done, start again
if self.player.stream_thread.is_finished() {
2 years ago
self.player.stream_thread = self.player.start_radio_stream(self.tor_required);
}
let _ = self.player.sink.play();
2 years ago
self.player.playing = true;
}
}
2 years ago
}
2 years ago
});
2 years ago
// 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
));
});
2 years ago
}
// 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();
2 years ago
if dur > Duration::from_secs(15) {
2 years ago
self.player.exif_date = SystemTime::now();
self.player.stream_exif = self.player.get_song_meta().unwrap();
}
}
2 years ago
ui.label("");
});
2 years ago
}
}