gui prints output from an http get to a configured URL
This commit is contained in:
@@ -41,6 +41,12 @@ pub struct GUI {
|
||||
pub release: PreSufFix,
|
||||
pub format: Option<String>,
|
||||
pub user: String,
|
||||
pub feedback: GUIFeedback,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct GUIFeedback {
|
||||
pub url: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
@@ -138,6 +144,12 @@ fn build_config_std() -> Config {
|
||||
false => None,
|
||||
},
|
||||
},
|
||||
feedback: GUIFeedback{
|
||||
url: match env::var("INPUT_GUI_FEEDBACK_URL") {
|
||||
Ok(url) => Some(url),
|
||||
Err(_) => None,
|
||||
},
|
||||
},
|
||||
}),
|
||||
device: None,
|
||||
udp: Some(UDP{
|
||||
|
||||
17
src/gui.rs
17
src/gui.rs
@@ -8,9 +8,10 @@ use handlebars::Handlebars;
|
||||
use serde_json::json;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use std::thread;
|
||||
use reqwest;
|
||||
|
||||
use crate::stream::OutputStream;
|
||||
use crate::config::GUI;
|
||||
use crate::config::{GUI,GUIFeedback};
|
||||
|
||||
pub fn main(cfg: GUI, output_stream: Box<dyn OutputStream>) -> iced::Result {
|
||||
let def: iced::Settings<()> = Settings::default();
|
||||
@@ -186,9 +187,11 @@ impl Application for Main {
|
||||
|
||||
fn new(flags: Self::Flags) -> (Self, Command<Message>) {
|
||||
let (sender, receiver) = std::sync::mpsc::channel();
|
||||
let feedback_cfg = flags.cfg.feedback.clone();
|
||||
thread::spawn(move || {
|
||||
Feedback{
|
||||
c: sender,
|
||||
cfg: feedback_cfg,
|
||||
}.listen()
|
||||
});
|
||||
return (Self {
|
||||
@@ -330,6 +333,7 @@ impl Application for Main {
|
||||
|
||||
struct Feedback {
|
||||
c: std::sync::mpsc::Sender<String>,
|
||||
cfg: GUIFeedback,
|
||||
}
|
||||
|
||||
impl Feedback {
|
||||
@@ -344,7 +348,16 @@ impl Feedback {
|
||||
}
|
||||
|
||||
fn read(&mut self) -> Option<String> {
|
||||
return Some(String::from(format!("feedback.read: {:?}", SystemTime::now())));
|
||||
return match &self.cfg.url {
|
||||
Some(url) => match reqwest::blocking::get(url) {
|
||||
Ok(resp) => match resp.text() {
|
||||
Ok(text) => Some(text),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
};
|
||||
}
|
||||
|
||||
fn write(&mut self, msg: String) {
|
||||
|
||||
15
src/testdata/http.go
vendored
Normal file
15
src/testdata/http.go
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
p := os.Getenv("PORT")
|
||||
if err := http.ListenAndServe(":"+p, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(os.Getenv("BODY")))
|
||||
})); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user