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/main.rs

132 lines
4.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 rodio::{Decoder, OutputStream, source::Source, Sink};
use eframe::egui;
// "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";
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 get_radio_sink() -> Sink {
thread::spawn(|| {
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("woww.ogg").expect("failed to create file");
io::copy(&mut res, &mut out).expect("failed to copy content");
});
std::thread::sleep(std::time::Duration::from_secs(3));
let (_stream, stream_handle) = OutputStream::try_default().unwrap();
let sink = Sink::try_new(&stream_handle).unwrap();
let file: io::BufReader<fs::File> = io::BufReader::new(fs::File::open("woww.ogg").unwrap());
let source: Decoder<io::BufReader<fs::File>> = Decoder::new(file).unwrap();
sink.append(source);
return sink
}
struct LzaGUI {
tor_started: bool,
to_data: String
}
impl Default for LzaGUI {
fn default() -> Self {
Self {
tor_started: false,
to_data: "".to_owned()
}
}
}
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");
let texture: egui::TextureHandle = ui.ctx().load_texture(
"rainbow",
egui::ColorImage::example(),
egui::TextureFilter::Linear
);
ui.add(egui::Image::new(texture.id(), texture.size_vec2()));
ui.label("Made by ya boi, lza_menace");
ui.hyperlink("https://lzahq.tech");
ui.separator();
if ui.button("Play WOW!Radio").clicked() {
println!("Playing radio...");
let sink: Sink = get_radio_sink();
sink.play();
}
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())),
);
}