From da459707becfe14b00d45b71e13e824665078bf9 Mon Sep 17 00:00:00 2001 From: Jordan Petridis Date: Fri, 5 Jan 2018 23:57:48 +0200 Subject: [PATCH] Wire up the callbacks to the client. --- hammond-gtk/src/manager.rs | 19 ++++++++++++++----- hammond-gtk/src/widgets/episode.rs | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/hammond-gtk/src/manager.rs b/hammond-gtk/src/manager.rs index ba26036..3f51146 100644 --- a/hammond-gtk/src/manager.rs +++ b/hammond-gtk/src/manager.rs @@ -2,8 +2,11 @@ use hammond_data::dbqueries; use hammond_downloader::downloader::get_episode; +use app::Action; + use std::collections::HashSet; use std::sync::{Arc, Mutex}; +use std::sync::mpsc::Sender; // use std::path::PathBuf; use std::thread; @@ -45,7 +48,7 @@ impl Manager { Manager::default() } - pub fn add(&self, id: i32, directory: &str) { + pub fn add(&self, id: i32, directory: &str, sender: Sender) { { let mut m = self.active.lock().unwrap(); m.insert(id); @@ -60,8 +63,11 @@ impl Manager { error!("Error: {}", err); }; - let mut m = list.lock().unwrap(); - m.remove(&id); + { + let mut m = list.lock().unwrap(); + m.remove(&id); + } + sender.send(Action::RefreshViews).unwrap(); }); } } @@ -80,6 +86,7 @@ mod tests { use std::path::Path; use std::{thread, time}; + use std::sync::mpsc::channel; #[test] // This test inserts an rss feed to your `XDG_DATA/hammond/hammond.db` so we make it explicit @@ -108,12 +115,14 @@ mod tests { .unwrap() }; + let (sender, _rx) = channel(); + let manager = Manager::new(); let download_fold = downloader::get_download_folder(&pd.title()).unwrap(); - manager.add(episode.rowid(), download_fold.as_str()); + manager.add(episode.rowid(), download_fold.as_str(), sender); // Give it soem time to download the file - thread::sleep(time::Duration::from_secs(20)); + thread::sleep(time::Duration::from_secs(40)); let final_path = format!("{}/{}.unknown", &download_fold, episode.rowid()); println!("{}", &final_path); diff --git a/hammond-gtk/src/widgets/episode.rs b/hammond-gtk/src/widgets/episode.rs index 8595883..bdf4146 100644 --- a/hammond-gtk/src/widgets/episode.rs +++ b/hammond-gtk/src/widgets/episode.rs @@ -239,7 +239,7 @@ fn on_download_clicked( let download_fold = downloader::get_download_folder(&pd_title).unwrap(); { let man = DOWNLOADS_MANAGER.lock().unwrap(); - man.add(ep.rowid(), &download_fold); + man.add(ep.rowid(), &download_fold, sender.clone()); } sender.send(Action::RefreshEpisodesViewBGR).unwrap(); }