added handling of request timeouts

This commit is contained in:
Wyatt J. Miller 2020-04-04 03:34:52 +01:00
parent 60d55f2f9e
commit c32454792f
3 changed files with 26 additions and 12 deletions

View File

@ -11,6 +11,7 @@ pub enum ActiveApp {
Crunchyroll,
Funimation,
VRV,
Nothing
}
// enum used to select what kind of TV you are using
@ -40,7 +41,7 @@ pub fn match_to_app(text: String) -> ActiveApp {
Some("Pandora") => ActiveApp::Pandora,
Some("Spotify") => ActiveApp::Spotify,
Some("Plex") => ActiveApp::Plex,
_ => ActiveApp::Roku,
_ => ActiveApp::Nothing,
}
}

View File

@ -44,11 +44,15 @@ impl Configuration {
port = self.port
);
let response = reqwest::get(&request).unwrap();
let document = Document::from_read(response).unwrap();
let next = document.find(Name("app")).next().unwrap();
next.text().to_string()
let response = get_request(&request);
match response {
Ok(res) => {
let document = Document::from_read(res).unwrap();
let next = document.find(Name("app")).next().unwrap();
next.text().to_string()
}
Err(_) => "_".to_string()
}
}
pub fn get_power_status(&self) -> String {
@ -58,11 +62,15 @@ impl Configuration {
port = self.port
);
let response = reqwest::get(&request).unwrap();
let document = Document::from_read(response).unwrap();
let next = document.find(Name("power-mode")).next().unwrap();
next.text().to_string()
let response = get_request(&request);
match response {
Ok(res) => {
let document = Document::from_read(res).unwrap();
let next = document.find(Name("power-mode")).next().unwrap();
next.text().to_string()
}
Err(_) => "_".to_string()
}
}
}
@ -76,3 +84,8 @@ pub fn init_config() -> Configuration {
config
}
pub fn get_request(request: &String) -> Result<reqwest::Response, reqwest::Error> {
let response = reqwest::get(request);
response
}

View File

@ -103,7 +103,7 @@ fn main() {
}
ws.write(brightness(data.iter().cloned(), 32)).unwrap();
},
_ => println!("Oops!"),
_ => println!("We don't know what app is running right now..."),
}
}
},