diff --git a/hammond-gtk/src/app.rs b/hammond-gtk/src/app.rs index c7ae2a5..82c0077 100644 --- a/hammond-gtk/src/app.rs +++ b/hammond-gtk/src/app.rs @@ -7,6 +7,7 @@ use gtk::SettingsExt as GtkSettingsExt; use gtk::prelude::*; use hammond_data::{Podcast, Source}; +use hammond_data::utils::delete_show; use appnotif::*; use headerbar::Header; @@ -17,6 +18,7 @@ use widgets::mark_all_watched; use std::sync::Arc; use std::sync::mpsc::{channel, Receiver, Sender}; use std::time::Duration; +use std::thread; #[derive(Clone, Debug)] pub enum Action { @@ -36,6 +38,7 @@ pub enum Action { HeaderBarShowUpdateIndicator, HeaderBarHideUpdateIndicator, MarkAllPlayerNotification(Arc), + RemoveShow(Arc), } #[derive(Debug)] @@ -198,6 +201,25 @@ impl App { // so there will be a nice animation. notif.show(); } + Ok(Action::RemoveShow(pd)) => { + let callback = clone!(pd => move || { + // Spawn a thread so it won't block the ui. + thread::spawn(clone!(pd => move || { + if let Err(err) = delete_show(&pd) { + error!("Something went wrong trying to remove {}", pd.title()); + error!("Error: {}", err); + } + })); + glib::Continue(false) + }); + + let text = format!("Unsubscribed from {}", pd.title()); + let notif = InAppNotification::new(text.into(), callback, sender.clone()); + overlay.add_overlay(¬if.revealer); + // We need to display the notification after the widget is added to the overlay + // so there will be a nice animation. + notif.show(); + } Err(_) => (), } diff --git a/hammond-gtk/src/widgets/show.rs b/hammond-gtk/src/widgets/show.rs index abe9a37..b17e1dd 100644 --- a/hammond-gtk/src/widgets/show.rs +++ b/hammond-gtk/src/widgets/show.rs @@ -7,7 +7,7 @@ use open; use hammond_data::Podcast; use hammond_data::dbqueries; -use hammond_data::utils::{delete_show, replace_extra_spaces}; +use hammond_data::utils::{replace_extra_spaces}; use app::Action; use utils::get_pixbuf_from_path; @@ -15,7 +15,6 @@ use widgets::episode::episodes_listbox; use std::sync::Arc; use std::sync::mpsc::Sender; -use std::thread; #[derive(Debug, Clone)] pub struct ShowWidget { @@ -141,13 +140,7 @@ fn on_unsub_button_clicked( // hack to get away without properly checking for none. // if pressed twice would panic. unsub_button.hide(); - // Spawn a thread so it won't block the ui. - thread::spawn(move || { - if let Err(err) = delete_show(&pd) { - error!("Something went wrong trying to remove {}", pd.title()); - error!("Error: {}", err); - } - }); + sender.send(Action::RemoveShow(pd))?; sender.send(Action::HeaderBarNormal)?; sender.send(Action::ShowShowsAnimated)?;