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.
166 lines
5.6 KiB
166 lines
5.6 KiB
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
|
|
|
use std::{thread, io, fs, time};
|
|
use libtor::{Tor, TorFlag, Error as libtorError, log as libtorLog};
|
|
use eframe::egui;
|
|
#[allow(unused_imports)]
|
|
use rodio::{Decoder, OutputStream, source::Source, Sink};
|
|
|
|
|
|
// "http://wowradiod6mhb4ignjqy5ghf5l42yh2yeumgeq3yi7gn7yqy3efhe5ad.onion"
|
|
// "http://wowradiof5wx62w4avdk5fwbvcoea2z4ul2q3awffn5vmfaa3vhlgiid.onion"
|
|
// "http://radio.poysibicsj73uhw7sjrv3fyopoyulrns4nlr5amyqdtafkqzlocd4qad.onion"
|
|
// "http://anonyradixhkgh5myfrkarggfnmdzzhhcgoy2v66uf7sml27to5n2tid.onion"
|
|
// "http://u2frppcgwqmoca7h3hu5l72upkwhcf2n6umrkqsnvnpahjynkre6sqyd.onion:8300/radio"
|
|
// "https://radio.wownero.com/wow.ogg"
|
|
|
|
const TOR_LOG: &str = &"/tmp/tor-rust/tor.log";
|
|
const RADIO_STREAM: &str = &"radio.ogg";
|
|
|
|
fn cleanup() {
|
|
let r: io::Result<()> = fs::remove_file(&RADIO_STREAM);
|
|
match r {
|
|
_ => ()
|
|
}
|
|
}
|
|
|
|
fn start_tor() -> thread::JoinHandle<Result<u8, libtorError>> {
|
|
let t: thread::JoinHandle<_> = Tor::new()
|
|
.flag(TorFlag::DataDirectory("/tmp/tor-rust".into()))
|
|
.flag(TorFlag::SocksPort(19050))
|
|
.flag(TorFlag::LogTo(libtorLog::LogLevel::Info, libtorLog::LogDestination::File(TOR_LOG.to_string())))
|
|
.start_background();
|
|
return t
|
|
}
|
|
|
|
fn clear_tor_log() -> io::Result<()> {
|
|
let r: io::Result<()> = fs::write(TOR_LOG, "");
|
|
return r
|
|
}
|
|
|
|
fn get_wow_price() -> String {
|
|
let url: &str = "https://tradeogre.com/api/v1/ticker/BTC-WOW";
|
|
let client: reqwest::blocking::Client = reqwest::blocking::ClientBuilder::new()
|
|
.timeout(time::Duration::from_secs(10))
|
|
.build()
|
|
.unwrap();
|
|
let res: String = client.get(url)
|
|
.send()
|
|
.unwrap()
|
|
.text()
|
|
.unwrap();
|
|
return res
|
|
}
|
|
|
|
fn start_radio_stream() -> thread::JoinHandle<()> {
|
|
let t: Result<thread::JoinHandle<()>, io::Error> = thread::Builder::new().name("radio_stream".to_string()).spawn(move || {
|
|
let mut res: reqwest::blocking::Response = reqwest::blocking::get("https://radio.wownero.com/wow.ogg").expect("request failed");
|
|
let mut out: fs::File = fs::File::create(RADIO_STREAM).expect("failed to create file");
|
|
io::copy(&mut res, &mut out).expect("failed to copy content");
|
|
});
|
|
return t.unwrap()
|
|
}
|
|
|
|
fn get_radio_source() -> Decoder<io::BufReader<fs::File>> {
|
|
// let _: fs::File = fs::File::create(RADIO_STREAM).expect("failed to create file");
|
|
let file: io::BufReader<fs::File> = io::BufReader::new(fs::File::open(RADIO_STREAM).unwrap());
|
|
let source: Decoder<io::BufReader<fs::File>> = Decoder::new(file).unwrap();
|
|
return source
|
|
}
|
|
|
|
fn get_radio_sink() -> Sink {
|
|
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
|
|
let sink = Sink::try_new(&stream_handle).unwrap();
|
|
return sink
|
|
}
|
|
|
|
struct LzaGUI {
|
|
tor_started: bool,
|
|
to_data: String,
|
|
sink: Sink
|
|
}
|
|
|
|
impl Default for LzaGUI {
|
|
fn default() -> Self {
|
|
Self {
|
|
tor_started: false,
|
|
to_data: "".to_owned(),
|
|
sink: get_radio_sink()
|
|
}
|
|
}
|
|
}
|
|
|
|
impl eframe::App for LzaGUI {
|
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
|
egui::CentralPanel::default().show(ctx, |ui| {
|
|
ui.heading("lza gui");
|
|
ui.label("Made by ya boi, lza_menace");
|
|
ui.hyperlink("https://lzahq.tech");
|
|
|
|
// ui.separator();
|
|
ui.horizontal(|ui| {
|
|
if ui.button("▶").clicked() {
|
|
let t: thread::JoinHandle<()> = start_radio_stream();
|
|
println!("Starting radio...streaming thread {:?}", t.thread());
|
|
thread::sleep(time::Duration::from_secs(3));
|
|
let source: Decoder<io::BufReader<fs::File>> = get_radio_source();
|
|
let _ = &self.sink.append(source);
|
|
let _ = &self.sink.play();
|
|
}
|
|
|
|
if ui.button("■").clicked() {
|
|
let _ = &self.sink.pause();
|
|
}
|
|
|
|
if ui.button("status").clicked() {
|
|
println!(
|
|
"is_paused: {}. empty: {}. len: {}. volume: {}.",
|
|
&self.sink.is_paused(),
|
|
&self.sink.empty(),
|
|
&self.sink.len(),
|
|
&self.sink.volume()
|
|
)
|
|
}
|
|
});
|
|
|
|
|
|
ui.separator();
|
|
if ui.button("Get TO Market Data").clicked() {
|
|
println!("Getting TO market data");
|
|
self.to_data = get_wow_price();
|
|
}
|
|
ui.label(&self.to_data);
|
|
|
|
ui.separator();
|
|
ui.heading("Tor");
|
|
if self.tor_started {
|
|
ui.label("Tor started.");
|
|
if ui.button("Clear Tor logs").clicked() {
|
|
let _r: io::Result<()> = clear_tor_log();
|
|
}
|
|
ui.collapsing("View Tor logs:", |ui| {
|
|
egui::ScrollArea::vertical().stick_to_bottom(true).show(ui, |ui| {
|
|
let contents = fs::read_to_string(TOR_LOG.to_string()).unwrap();
|
|
ui.label(contents);
|
|
});
|
|
});
|
|
} else {
|
|
if ui.button("Start Tor").clicked() {
|
|
let _t: thread::JoinHandle<Result<u8, libtorError>> = start_tor();
|
|
self.tor_started = true;
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
let options = eframe::NativeOptions::default();
|
|
eframe::run_native(
|
|
"lza gui",
|
|
options,
|
|
Box::new(|_cc| Box::new(LzaGUI::default())),
|
|
);
|
|
let _ = cleanup();
|
|
}
|