Commit ea70addb authored by Jordan Petridis's avatar Jordan Petridis 🌱

Removed some unwrap()s.

parent 87a259e1
......@@ -613,7 +613,6 @@ impl<'a> Source {
fn update_etag(&mut self, req: &reqwest::Response) -> Result<()> {
let headers = req.headers();
// let etag = headers.get_raw("ETag").unwrap();
let etag = headers.get::<ETag>();
let lmod = headers.get::<LastModified>();
......
......@@ -68,29 +68,33 @@ pub fn add(id: i32, directory: &str, sender: Sender<Action>) {
let prog = Arc::new(Mutex::new(Progress::default()));
{
let mut m = ACTIVE_DOWNLOADS.write().unwrap();
m.insert(id, prog.clone());
}
{
let m = ACTIVE_DOWNLOADS.read().unwrap();
info!("ACTIVE DOWNLOADS: {:#?}", m);
ACTIVE_DOWNLOADS
.write()
.ok()
.map(|mut m| m.insert(id, prog.clone()));
}
// {
// let m = ACTIVE_DOWNLOADS.read().unwrap();
// info!("ACTIVE DOWNLOADS: {:#?}", m);
// }
let dir = directory.to_owned();
thread::spawn(move || {
let episode = dbqueries::get_episode_from_rowid(id).unwrap();
let e = get_episode(&mut episode.into(), dir.as_str(), Some(prog));
if let Err(err) = e {
error!("Error: {}", err);
};
{
let mut m = ACTIVE_DOWNLOADS.write().unwrap();
m.remove(&id);
if let Ok(episode) = dbqueries::get_episode_from_rowid(id) {
get_episode(&mut episode.into(), dir.as_str(), Some(prog))
.err()
.map(|err| {
error!("Error while trying to download an episode");
error!("Error: {}", err);
});
{
ACTIVE_DOWNLOADS.write().ok().map(|mut x| x.remove(&id));
}
sender.send(Action::RefreshEpisodesView).unwrap();
sender.send(Action::RefreshWidget).unwrap();
}
sender.send(Action::RefreshEpisodesView).unwrap();
sender.send(Action::RefreshWidget).unwrap();
});
}
......
......@@ -205,10 +205,7 @@ impl EpisodesViewWidget {
let image: gtk::Image = builder.get_object("cover").unwrap();
if let Ok(pd) = dbqueries::get_podcast_cover_from_id(episode.podcast_id()) {
let img = get_pixbuf_from_path(&pd, 64);
if let Some(i) = img {
image.set_from_pixbuf(&i);
}
get_pixbuf_from_path(&pd, 64).map(|img| image.set_from_pixbuf(&img));
}
let ep = EpisodeWidget::new(episode, sender.clone());
......
......@@ -205,13 +205,15 @@ impl EpisodeWidget {
.parse::<i32>()
.unwrap();
let prog_struct = {
let m = manager::ACTIVE_DOWNLOADS.read().unwrap();
if !m.contains_key(&id) {
return;
};
m.get(&id).cloned()
};
let prog_struct = || -> Option<_> {
if let Ok(m) = manager::ACTIVE_DOWNLOADS.read() {
if !m.contains_key(&id) {
return None;
};
return m.get(&id).cloned();
}
None
}();
let progress_bar = self.progress.clone();
let total_size = self.total_size.clone();
......@@ -237,11 +239,15 @@ impl EpisodeWidget {
}
fn on_download_clicked(ep: &EpisodeWidgetQuery, sender: Sender<Action>) {
let pd = dbqueries::get_podcast_from_id(ep.podcast_id()).unwrap();
let download_fold = downloader::get_download_folder(&pd.title().to_owned()).unwrap();
let download_fold = dbqueries::get_podcast_from_id(ep.podcast_id())
.ok()
.map(|pd| downloader::get_download_folder(&pd.title().to_owned()).ok())
.and_then(|x| x);
// Start a new download.
manager::add(ep.rowid(), &download_fold, sender.clone());
if let Some(fold) = download_fold {
manager::add(ep.rowid(), &fold, sender.clone());
}
// Update Views
sender.send(Action::RefreshEpisodesView).unwrap();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment