added handling of request timeouts
This commit is contained in:
parent
60d55f2f9e
commit
c32454792f
@ -11,6 +11,7 @@ pub enum ActiveApp {
|
|||||||
Crunchyroll,
|
Crunchyroll,
|
||||||
Funimation,
|
Funimation,
|
||||||
VRV,
|
VRV,
|
||||||
|
Nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
// enum used to select what kind of TV you are using
|
// 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("Pandora") => ActiveApp::Pandora,
|
||||||
Some("Spotify") => ActiveApp::Spotify,
|
Some("Spotify") => ActiveApp::Spotify,
|
||||||
Some("Plex") => ActiveApp::Plex,
|
Some("Plex") => ActiveApp::Plex,
|
||||||
_ => ActiveApp::Roku,
|
_ => ActiveApp::Nothing,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,12 +44,16 @@ impl Configuration {
|
|||||||
port = self.port
|
port = self.port
|
||||||
);
|
);
|
||||||
|
|
||||||
let response = reqwest::get(&request).unwrap();
|
let response = get_request(&request);
|
||||||
let document = Document::from_read(response).unwrap();
|
match response {
|
||||||
|
Ok(res) => {
|
||||||
|
let document = Document::from_read(res).unwrap();
|
||||||
let next = document.find(Name("app")).next().unwrap();
|
let next = document.find(Name("app")).next().unwrap();
|
||||||
|
|
||||||
next.text().to_string()
|
next.text().to_string()
|
||||||
}
|
}
|
||||||
|
Err(_) => "_".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_power_status(&self) -> String {
|
pub fn get_power_status(&self) -> String {
|
||||||
let request = format!(
|
let request = format!(
|
||||||
@ -58,12 +62,16 @@ impl Configuration {
|
|||||||
port = self.port
|
port = self.port
|
||||||
);
|
);
|
||||||
|
|
||||||
let response = reqwest::get(&request).unwrap();
|
let response = get_request(&request);
|
||||||
let document = Document::from_read(response).unwrap();
|
match response {
|
||||||
|
Ok(res) => {
|
||||||
|
let document = Document::from_read(res).unwrap();
|
||||||
let next = document.find(Name("power-mode")).next().unwrap();
|
let next = document.find(Name("power-mode")).next().unwrap();
|
||||||
|
|
||||||
next.text().to_string()
|
next.text().to_string()
|
||||||
}
|
}
|
||||||
|
Err(_) => "_".to_string()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab the config
|
// grab the config
|
||||||
@ -76,3 +84,8 @@ pub fn init_config() -> Configuration {
|
|||||||
|
|
||||||
config
|
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();
|
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