added handling of request timeouts
This commit is contained in:
parent
60d55f2f9e
commit
c32454792f
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,16 @@ impl Configuration {
|
||||
port = self.port
|
||||
);
|
||||
|
||||
let response = reqwest::get(&request).unwrap();
|
||||
let document = Document::from_read(response).unwrap();
|
||||
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 {
|
||||
let request = format!(
|
||||
@ -58,12 +62,16 @@ impl Configuration {
|
||||
port = self.port
|
||||
);
|
||||
|
||||
let response = reqwest::get(&request).unwrap();
|
||||
let document = Document::from_read(response).unwrap();
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// grab the config
|
||||
@ -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
|
||||
}
|
@ -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..."),
|
||||
}
|
||||
}
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user