EpisodeWidget: Remove unwrap on that could occur if an invalid path was passed.
This commit is contained in:
parent
9dfb18a487
commit
1135d77147
@ -116,7 +116,10 @@ impl EpisodeWidget {
|
|||||||
self.set_date(episode.epoch());
|
self.set_date(episode.epoch());
|
||||||
|
|
||||||
// Show or hide the play/delete/download buttons upon widget initialization.
|
// Show or hide the play/delete/download buttons upon widget initialization.
|
||||||
self.show_buttons(episode.local_uri());
|
if let Err(err) = self.show_buttons(episode.local_uri()) {
|
||||||
|
error!("Failed to determine play/download button state.");
|
||||||
|
error!("Error: {}", err);
|
||||||
|
}
|
||||||
|
|
||||||
// Set the size label.
|
// Set the size label.
|
||||||
if let Err(err) = self.set_total_size(episode.length()) {
|
if let Err(err) = self.set_total_size(episode.length()) {
|
||||||
@ -157,11 +160,13 @@ impl EpisodeWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Show or hide the play/delete/download buttons upon widget initialization.
|
/// Show or hide the play/delete/download buttons upon widget initialization.
|
||||||
fn show_buttons(&self, local_uri: Option<&str>) {
|
fn show_buttons(&self, local_uri: Option<&str>) -> Result<(), Error> {
|
||||||
if local_uri.is_some() && Path::new(local_uri.unwrap()).exists() {
|
let path = local_uri.ok_or_else(|| format_err!("Path is None"))?;
|
||||||
|
if Path::new(path).exists() {
|
||||||
self.download.hide();
|
self.download.hide();
|
||||||
self.play.show();
|
self.play.show();
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determine the title state.
|
/// Determine the title state.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user