From 1587afc887ae89c904d6ab710e396b100f1708dc Mon Sep 17 00:00:00 2001 From: aprzn Date: Sat, 26 Aug 2023 16:36:45 -0400 Subject: [PATCH] figuring out the request --- NONGfisher/Cargo.lock | 2 ++ NONGfisher/Cargo.toml | 2 +- NONGfisher/src/main.rs | 36 +++++++++++++++++++++++++++++------- 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/NONGfisher/Cargo.lock b/NONGfisher/Cargo.lock index 094d46d..8057d53 100644 --- a/NONGfisher/Cargo.lock +++ b/NONGfisher/Cargo.lock @@ -2380,6 +2380,8 @@ dependencies = [ "once_cell", "rustls", "rustls-webpki 0.100.2", + "serde", + "serde_json", "url", "webpki-roots", ] diff --git a/NONGfisher/Cargo.toml b/NONGfisher/Cargo.toml index a4eedce..766315e 100644 --- a/NONGfisher/Cargo.toml +++ b/NONGfisher/Cargo.toml @@ -10,4 +10,4 @@ eframe = "0.22.0" notify = "6.1.1" serde = { version = "1.0.186", features = ["derive"] } serde_json = "1.0.105" -ureq = "2.7.1" +ureq = { version = "2.7.1", features = ["json"] } diff --git a/NONGfisher/src/main.rs b/NONGfisher/src/main.rs index eb418a2..5ea36c0 100644 --- a/NONGfisher/src/main.rs +++ b/NONGfisher/src/main.rs @@ -1,4 +1,6 @@ #![allow(dead_code)] +use std::{sync::mpsc, thread}; + use eframe::{ egui::{CentralPanel, Context, Layout, TextFormat, Visuals}, emath::Align, @@ -42,15 +44,26 @@ enum Event { IdSubmit { id: String }, } -enum App { +enum State { IdSelect { search_string: String, enabled: bool }, } +struct App { + state: State, + event_tx: mpsc::Sender, + event_rx: mpsc::Receiver, +} + impl App { fn new() -> Self { - Self::IdSelect { - search_string: String::new(), - enabled: true + let (event_tx, event_rx) = mpsc::channel(); + Self { + state: State::IdSelect { + search_string: String::new(), + enabled: true, + }, + event_tx, + event_rx, } } @@ -83,8 +96,8 @@ impl App { ui.with_layout(Layout::top_down(Align::Center), |ui| { ui.label(title_text); - match self { - Self::IdSelect { search_string, enabled } => { + match &mut self.state { + State::IdSelect { search_string, enabled } => { ui.label("Enter level ID:"); ui.add_enabled_ui(*enabled, |ui| { ui.text_edit_singleline(search_string).request_focus(); @@ -104,7 +117,16 @@ impl App { for event in events { match event { Event::IdSubmit { id } => { - *self = Self::IdSelect { search_string: id, enabled: false }; + let tx = self.event_tx.clone(); + self.state = State::IdSelect { search_string: id.clone(), enabled: false }; + thread::spawn(move || { + let res = ureq::post("http://www.boomlings.com/database/downloadGJLevel22.php") + .set("User-Agent", "") + .send_form(&[ + ("levelID", &id), + ("secret", "Wmfd2893gb7"), + ]); + }); }, } }