use std ::time ::{ Duration , SystemTime } ;
use eframe ::egui ;
use egui ::FontFamily ::Proportional ;
use egui ::FontId ;
use egui ::TextStyle ::* ;
use crate ::player ::Player ;
use crate ::tor ::GuiTor ;
use crate ::stats ::Market ;
use libtor ::Error as libtorError ;
pub struct App {
pub player : Player ,
pub tor_required : bool ,
pub tor_started : bool ,
pub tor_connected : bool ,
pub to_data : String ,
pub show_irc : bool ,
pub irc_message : String ,
pub show_market_data : bool ,
pub market : Market
}
impl Default for App {
fn default ( ) -> Self {
Self {
tor_started : false ,
tor_required : true ,
tor_connected : false ,
show_market_data : false ,
show_irc : false ,
to_data : "" . to_owned ( ) ,
player : Player ::default ( ) ,
market : Market ::new ( ) ,
irc_message : "" . to_owned ( )
}
}
}
fn show_boolmoji ( b : bool ) -> String {
if b { return "✔" . to_owned ( ) } else { return "☠" . 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" ) ;
} ) ;
egui ::CentralPanel ::default ( ) . show ( ctx , | ui | {
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" ) ;
}
} ) ;
ui . separator ( ) ;
if self . tor_required {
if self . tor_started {
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 )
)
)
) ;
} else {
if ui . button ( "Connect to the Tor network" ) . clicked ( ) {
let _t : std ::thread ::JoinHandle < Result < u8 , libtorError > > = GuiTor ::start_tor ( ) ;
self . tor_started = true ;
self . tor_connected = true ;
}
}
}
if self . show_market_data {
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 | {
ui . label ( "CURRENT PRICE" ) ;
ui . heading ( egui ::RichText ::new ( md [ "current_price" ] [ "sats" ] . to_string ( ) ) . strong ( ) ) ;
ui . label ( "SATS" ) ;
} ) ;
ui . vertical ( | ui | {
ui . label ( "ATH" ) ;
ui . heading ( egui ::RichText ::new ( md [ "ath" ] [ "sats" ] . to_string ( ) ) . strong ( ) ) ;
ui . label ( "SATS" ) ;
} ) ;
ui . vertical ( | ui | {
ui . label ( "ATL" ) ;
ui . heading ( egui ::RichText ::new ( md [ "atl" ] [ "sats" ] . to_string ( ) ) . strong ( ) ) ;
ui . label ( "SATS" ) ;
} ) ;
ui . vertical ( | ui | {
ui . label ( "MARKET CAP" ) ;
ui . heading ( egui ::RichText ::new ( md [ "market_cap" ] [ "sats" ] . to_string ( ) ) . strong ( ) ) ;
ui . label ( "SATS" ) ;
} ) ;
} ) ;
}
} ) ;
// Show volume controls
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 ! self . tor_connected & & self . tor_required {
ui . label ( "Connect to the Tor network first." ) ;
} else {
if ui . button ( "▶" ) . clicked ( ) {
if ! self . tor_connected & & self . tor_required {
return ( ) ;
}
// If stream thread is done, start again
if self . player . stream_thread . is_finished ( ) {
self . player . stream_thread = self . player . start_radio_stream ( self . tor_required ) ;
}
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 ( "" ) ;
} ) ;
}
}