diff --git a/src/app.rs b/src/app.rs index f7fc5bf..5177728 100644 --- a/src/app.rs +++ b/src/app.rs @@ -4,6 +4,7 @@ use egui::FontFamily::Proportional; use egui::FontId; use egui::TextStyle::*; use crate::player::Player; +use crate::tor::GuiTor; use libtor::Error as libtorError; pub struct App { @@ -59,7 +60,7 @@ impl eframe::App for App { if self.tor_started { ui.label("Tor started."); if ui.button("Clear Tor logs").clicked() { - let _r: std::io::Result<()> = crate::clear_tor_log(); + let _r: std::io::Result<()> = GuiTor::clear_log(); } if ui.button("Check Proxy").clicked() { if self.player.check_proxy() { @@ -74,7 +75,7 @@ impl eframe::App for App { }); } else { if ui.button("Connect to the Tor network").clicked() { - let _t: std::thread::JoinHandle> = crate::start_tor(); + let _t: std::thread::JoinHandle> = GuiTor::start_tor(); self.tor_started = true; self.tor_connected = true; } diff --git a/src/main.rs b/src/main.rs index 9d11512..0c2a1aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,12 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -#[allow(dead_code)] pub use crate::player::Player; pub use crate::app::App; -// use std::{thread, io, fs, time}; -use libtor::{Tor, TorFlag, Error as libtorError, log as libtorLog}; -#[allow(unused_imports)] -use rodio::{Decoder, OutputStream, source::Source, Sink}; - mod app; mod player; +mod tor; // "http://wowradiod6mhb4ignjqy5ghf5l42yh2yeumgeq3yi7gn7yqy3efhe5ad.onion" // "http://wowradiof5wx62w4avdk5fwbvcoea2z4ul2q3awffn5vmfaa3vhlgiid.onion" @@ -31,34 +26,6 @@ fn cleanup() { } } -fn start_tor() -> std::thread::JoinHandle> { - let t: std::thread::JoinHandle<_> = Tor::new() - .flag(TorFlag::DataDirectory(TOR_DATA.to_owned())) - .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() -> std::io::Result<()> { - let r: std::io::Result<()> = std::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 main() { let (_stream, stream_handle) = rodio::OutputStream::try_default().unwrap(); let sink: rodio::Sink = rodio::Sink::try_new(&stream_handle).unwrap(); diff --git a/src/stats.rs b/src/stats.rs new file mode 100644 index 0000000..4a49781 --- /dev/null +++ b/src/stats.rs @@ -0,0 +1,16 @@ + + + +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(std::time::Duration::from_secs(10)) + .build() + .unwrap(); + let res: String = client.get(url) + .send() + .unwrap() + .json() + .unwrap(); + return res +} \ No newline at end of file diff --git a/src/tor.rs b/src/tor.rs new file mode 100644 index 0000000..cf4ca1f --- /dev/null +++ b/src/tor.rs @@ -0,0 +1,19 @@ +use libtor::{Tor, TorFlag, Error as libtorError, log as libtorLog}; + +pub struct GuiTor {} +impl GuiTor { + pub fn start_tor() -> std::thread::JoinHandle> { + let t: std::thread::JoinHandle<_> = Tor::new() + .flag(TorFlag::DataDirectory(crate::TOR_DATA.to_owned())) + .flag(TorFlag::SocksPort(19050)) + .flag(TorFlag::LogTo(libtorLog::LogLevel::Info, libtorLog::LogDestination::File(crate::TOR_LOG.to_string()))) + .start_background(); + return t + } + + pub fn clear_log() -> std::io::Result<()> { + let r: std::io::Result<()> = std::fs::write(crate::TOR_LOG, ""); + return r + } +} +