@ -1,4 +1,6 @@
use std ::time ::{ Duration , SystemTime } ;
use std ::io ::Write ;
use std ::net ::TcpStream ;
use eframe ::egui ;
use egui ::FontFamily ::Proportional ;
use egui ::FontId ;
@ -20,7 +22,9 @@ pub struct App {
pub show_irc : bool ,
pub irc_message : String ,
pub irc_connected : bool ,
pub show_market_data : bool
pub show_market_data : bool ,
pub show_radio : bool ,
pub irc_stream : Result < TcpStream , std ::io ::Error > ,
}
impl Default for App {
@ -36,7 +40,9 @@ impl Default for App {
show_irc : false ,
irc_connected : false ,
to_data : "" . to_owned ( ) ,
irc_message : "" . to_owned ( )
irc_message : "" . to_owned ( ) ,
show_radio : true ,
irc_stream : TcpStream ::connect ( "0.0.0.0:0" )
}
}
}
@ -73,87 +79,93 @@ 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 . separator ( ) ;
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 ) ) ;
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 ( ) {
// WOW!Radio
if self . show_radio {
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 ) ) ;
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 ( )
}
// 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 ) ;
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 ;
}
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 ( 15 ) {
self . player . exif_date = SystemTime ::now ( ) ;
self . player . stream_exif = self . player . get_song_meta ( ) . unwrap ( ) ;
// 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
) ) ;
} ) ;
}
if ui . button ( "!tune - i love this song!" ) . clicked ( ) {
let _ = self . irc . send_tune ( ) ;
// 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 ( 15 ) {
self . player . exif_date = SystemTime ::now ( ) ;
self . player . stream_exif = self . player . get_song_meta ( ) . unwrap ( ) ;
}
if ui . button ( "| +1 |" ) . clicked ( ) {
let _ = self . irc . send_tune ( ) ;
}
}
ui . separator ( ) ;
}
ui . separator ( ) ;
// Tor
if self . tor_required {
@ -161,7 +173,7 @@ impl eframe::App for App {
ui . label (
egui ::RichText ::new (
format! (
"Tor Started: {} \nTor Connected: {}\n Proxy Up: {}",
"Tor Started: {} Tor Connected: {} Proxy Up: {}",
show_boolmoji ( self . tor_started ) ,
show_boolmoji ( self . tor_connected ) ,
show_boolmoji ( self . tor_connected )
@ -179,16 +191,19 @@ impl eframe::App for App {
// IRC
if self . show_irc & & ! self . irc_connected {
self . irc . run ( ) . expect ( "wtf mate" ) ;
self . irc _stream = self . irc . run ( ) ;
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 . text_edit_singleline ( & mut self . irc_message ) ;
if ui . button ( "> Send <" ) . clicked ( ) {
// send_cmd(self.irc.)
self . irc_message = "" . to_owned ( ) ;
}
ui . horizontal ( | ui | {
ui . text_edit_singleline ( & mut self . irc_message ) ;
if ui . button ( "> Send <" ) . clicked ( ) {
let _ = self . irc_stream . as_ref ( ) . unwrap ( ) . write ( self . irc_message . as_bytes ( ) ) ;
// let _ = crate::irc::send_cmd(&self.irc_stream.as_ref(), cmd, "");
self . irc_message = "" . to_owned ( ) ;
}
} ) ;
} ) ;
}