diff --git a/Cargo.lock b/Cargo.lock index 3919437..27c165e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1519,6 +1519,7 @@ dependencies = [ "crossbeam-channel 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "fragile 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "gdk 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "gdk-pixbuf 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "gio 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1538,7 +1539,6 @@ dependencies = [ "rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "reqwest 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", - "send-cell 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1861,14 +1861,6 @@ dependencies = [ "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "send-cell" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "fragile 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "serde" version = "0.9.15" @@ -2685,7 +2677,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "dfa44ee9c54ce5eecc9de7d5acbad112ee58755239381f687e564004ba4a2332" "checksum security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "5421621e836278a0b139268f36eee0dc7e389b784dc3f79d8f11aabadf41bead" -"checksum send-cell 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "369add9433969659158b4bcc0c471c183889565a00c426f4d1d5447efe17f401" "checksum serde 0.9.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34b623917345a631dc9608d5194cc206b3fe6c3554cd1c75b937e55e285254af" "checksum serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3adf19c07af6d186d91dae8927b83b0553d07ca56cbf7f2f32560455c91920" "checksum serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)" = "3525a779832b08693031b8ecfb0de81cd71cfd3812088fafe9a7496789572124" diff --git a/podcasts-gtk/Cargo.toml b/podcasts-gtk/Cargo.toml index f029745..6951287 100644 --- a/podcasts-gtk/Cargo.toml +++ b/podcasts-gtk/Cargo.toml @@ -19,10 +19,10 @@ log = "0.4.3" loggerv = "0.7.1" open = "1.2.1" rayon = "1.0.2" -send-cell = "0.1.3" url = "1.7.1" failure = "0.1.1" failure_derive = "0.1.1" +fragile = "0.2.1" regex = "1.0.2" reqwest = "0.8.6" serde_json = "1.0.24" diff --git a/podcasts-gtk/src/app.rs b/podcasts-gtk/src/app.rs index 638b68d..ea7ab5f 100644 --- a/podcasts-gtk/src/app.rs +++ b/podcasts-gtk/src/app.rs @@ -6,8 +6,8 @@ use gtk; use gtk::prelude::*; use crossbeam_channel::{unbounded, Receiver, Sender}; +use fragile::Fragile; use podcasts_data::Show; -use send_cell::SendCell; use headerbar::Header; use prefs::Prefs; @@ -57,7 +57,7 @@ pub enum Action { RemoveShow(Arc), ErrorNotification(String), InitEpisode(i32), - InitShowMenu(SendCell), + InitShowMenu(Fragile), } #[derive(Debug, Clone)] @@ -287,8 +287,8 @@ impl App { debug_assert!(res.is_ok()); } Action::InitShowMenu(s) => { - let menu = s.borrow(); - self.headerbar.set_secondary_menu(&menu.container); + let menu = &s.get().container; + self.headerbar.set_secondary_menu(menu); } } } diff --git a/podcasts-gtk/src/main.rs b/podcasts-gtk/src/main.rs index 36e6be6..eaf8816 100644 --- a/podcasts-gtk/src/main.rs +++ b/podcasts-gtk/src/main.rs @@ -60,6 +60,7 @@ extern crate pretty_assertions; extern crate chrono; extern crate crossbeam_channel; +extern crate fragile; extern crate html2text; extern crate humansize; extern crate loggerv; @@ -69,7 +70,6 @@ extern crate podcasts_downloader; extern crate rayon; extern crate regex; extern crate reqwest; -extern crate send_cell; extern crate serde_json; extern crate url; diff --git a/podcasts-gtk/src/utils.rs b/podcasts-gtk/src/utils.rs index ccc7214..20155c1 100644 --- a/podcasts-gtk/src/utils.rs +++ b/podcasts-gtk/src/utils.rs @@ -10,10 +10,10 @@ use gtk::{IsA, Widget}; use chrono::prelude::*; use crossbeam_channel::{unbounded, Sender}; use failure::Error; +use fragile::Fragile; use rayon; use regex::Regex; use reqwest; -use send_cell::SendCell; use serde_json::Value; // use podcasts_data::feed; @@ -213,7 +213,7 @@ where } lazy_static! { - static ref CACHED_PIXBUFS: RwLock>>> = + static ref CACHED_PIXBUFS: RwLock>>> = { RwLock::new(HashMap::new()) }; static ref COVER_DL_REGISTRY: RwLock> = RwLock::new(HashSet::new()); static ref THREADPOOL: rayon::ThreadPool = rayon::ThreadPoolBuilder::new().build().unwrap(); @@ -248,12 +248,12 @@ pub fn set_image_from_path(image: >k::Image, show_id: i32, size: u32) -> Resul if let Some(guard) = hashmap.get(&(show_id, size)) { guard .lock() - .map_err(|err| format_err!("SendCell Mutex: {}", err)) - .and_then(|sendcell| { - sendcell + .map_err(|err| format_err!("Fragile Mutex: {}", err)) + .and_then(|fragile| { + fragile .try_get() .map(|px| image.set_from_pixbuf(px)) - .ok_or_else(|| format_err!("Pixbuf was accessed from a different thread")) + .map_err(From::from) })?; return Ok(()); @@ -278,7 +278,7 @@ pub fn set_image_from_path(image: >k::Image, show_id: i32, size: u32) -> Resul if let Ok(path) = path { if let Ok(px) = Pixbuf::new_from_file_at_scale(&path, s, s, true) { if let Ok(mut hashmap) = CACHED_PIXBUFS.write() { - hashmap.insert((show_id, size), Mutex::new(SendCell::new(px.clone()))); + hashmap.insert((show_id, size), Mutex::new(Fragile::new(px.clone()))); image.set_from_pixbuf(&px); } } diff --git a/podcasts-gtk/src/widgets/home_view.rs b/podcasts-gtk/src/widgets/home_view.rs index 85713b1..e5106d1 100644 --- a/podcasts-gtk/src/widgets/home_view.rs +++ b/podcasts-gtk/src/widgets/home_view.rs @@ -5,9 +5,9 @@ use gtk; use gtk::prelude::*; use crossbeam_channel::Sender; +use fragile::Fragile; use podcasts_data::dbqueries; use podcasts_data::EpisodeWidgetModel; -use send_cell::SendCell; use app::Action; use utils::{self, lazy_load_full}; @@ -18,7 +18,7 @@ use std::rc::Rc; use std::sync::Mutex; lazy_static! { - pub static ref EPISODES_VIEW_VALIGNMENT: Mutex>> = + pub static ref EPISODES_VIEW_VALIGNMENT: Mutex>> = Mutex::new(None); } @@ -126,11 +126,15 @@ impl HomeView { .lock() .map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?; - if let Some(ref sendcell) = *guard { + if let Some(ref fragile) = *guard { // Copy the vertical scrollbar adjustment from the old view into the new one. - sendcell + let res = fragile .try_get() - .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)); + .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)) + .map_err(From::from); + + debug_assert!(res.is_ok()); + return res; } Ok(()) @@ -143,7 +147,7 @@ impl HomeView { .scrolled_window .get_vadjustment() .ok_or_else(|| format_err!("Could not get the adjustment"))?; - *guard = Some(SendCell::new(adj)); + *guard = Some(Fragile::new(adj)); info!("Saved episodes_view alignment."); } diff --git a/podcasts-gtk/src/widgets/player.rs b/podcasts-gtk/src/widgets/player.rs index a5deb43..fe0a76f 100644 --- a/podcasts-gtk/src/widgets/player.rs +++ b/podcasts-gtk/src/widgets/player.rs @@ -11,7 +11,7 @@ use glib::SignalHandlerId; use chrono::NaiveTime; use crossbeam_channel::Sender; use failure::Error; -use send_cell::SendCell; +use fragile::Fragile; use podcasts_data::{dbqueries, USER_AGENT}; use podcasts_data::{EpisodeWidgetModel, ShowCoverModel}; @@ -300,25 +300,25 @@ impl PlayerWidget { })); // The followign callbacks require `Send` but are handled by the gtk main loop - let weak = SendCell::new(Rc::downgrade(s)); + let weak = Fragile::new(Rc::downgrade(s)); // Update the duration label and the slider s.player.connect_duration_changed(clone!(weak => move |_, clock| { - weak.borrow() + weak.get() .upgrade() .map(|p| p.timer.on_duration_changed(Duration(clock))); })); // Update the position label and the slider s.player.connect_position_updated(clone!(weak => move |_, clock| { - weak.borrow() + weak.get() .upgrade() .map(|p| p.timer.on_position_updated(Position(clock))); })); // Reset the slider to 0 and show a play button s.player.connect_end_of_stream(clone!(weak => move |_| { - weak.borrow() + weak.get() .upgrade() .map(|p| p.stop()); })); diff --git a/podcasts-gtk/src/widgets/show.rs b/podcasts-gtk/src/widgets/show.rs index bba8996..05ef772 100644 --- a/podcasts-gtk/src/widgets/show.rs +++ b/podcasts-gtk/src/widgets/show.rs @@ -4,9 +4,9 @@ use gtk::prelude::*; use crossbeam_channel::Sender; use failure::Error; +use fragile::Fragile; use html2text; use rayon; -use send_cell::SendCell; use podcasts_data::dbqueries; use podcasts_data::Show; @@ -19,7 +19,7 @@ use std::rc::Rc; use std::sync::{Arc, Mutex}; lazy_static! { - static ref SHOW_WIDGET_VALIGNMENT: Mutex)>> = + static ref SHOW_WIDGET_VALIGNMENT: Mutex)>> = Mutex::new(None); } @@ -60,7 +60,7 @@ impl ShowWidget { pdw.init(&pd); let menu = ShowMenu::new(&pd, &pdw.episodes, &sender); - sender.send(Action::InitShowMenu(SendCell::new(menu))); + sender.send(Action::InitShowMenu(Fragile::new(menu))); let pdw = Rc::new(pdw); let res = populate_listbox(&pdw, pd.clone(), sender); @@ -95,7 +95,7 @@ impl ShowWidget { .scrolled_window .get_vadjustment() .ok_or_else(|| format_err!("Could not get the adjustment"))?; - *guard = Some((oldid, SendCell::new(adj))); + *guard = Some((oldid, Fragile::new(adj))); debug!("Widget Alignment was saved with ID: {}.", oldid); } @@ -108,7 +108,7 @@ impl ShowWidget { .lock() .map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?; - if let Some((oldid, ref sendcell)) = *guard { + if let Some((oldid, ref fragile)) = *guard { // Only copy the old scrollbar if both widget's represent the same podcast. debug!("PID: {}", pd.id()); debug!("OLDID: {}", oldid); @@ -118,9 +118,13 @@ impl ShowWidget { }; // Copy the vertical scrollbar adjustment from the old view into the new one. - sendcell + let res = fragile .try_get() - .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)); + .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)) + .map_err(From::from); + + debug_assert!(res.is_ok()); + return res; } Ok(()) diff --git a/podcasts-gtk/src/widgets/shows_view.rs b/podcasts-gtk/src/widgets/shows_view.rs index b19db6e..8eac935 100644 --- a/podcasts-gtk/src/widgets/shows_view.rs +++ b/podcasts-gtk/src/widgets/shows_view.rs @@ -3,7 +3,7 @@ use gtk::prelude::*; use crossbeam_channel::Sender; use failure::Error; -use send_cell::SendCell; +use fragile::Fragile; use podcasts_data::dbqueries; use podcasts_data::Show; @@ -17,7 +17,7 @@ use std::sync::Arc; use std::sync::Mutex; lazy_static! { - static ref SHOWS_VIEW_VALIGNMENT: Mutex>> = Mutex::new(None); + static ref SHOWS_VIEW_VALIGNMENT: Mutex>> = Mutex::new(None); } #[derive(Debug, Clone)] @@ -65,11 +65,15 @@ impl ShowsView { .lock() .map_err(|err| format_err!("Failed to lock widget align mutex: {}", err))?; - if let Some(ref sendcell) = *guard { + if let Some(ref fragile) = *guard { // Copy the vertical scrollbar adjustment from the old view into the new one. - sendcell + let res = fragile .try_get() - .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)); + .map(|x| utils::smooth_scroll_to(&self.scrolled_window, &x)) + .map_err(From::from); + + debug_assert!(res.is_ok()); + return res; } Ok(()) @@ -82,7 +86,7 @@ impl ShowsView { .scrolled_window .get_vadjustment() .ok_or_else(|| format_err!("Could not get the adjustment"))?; - *guard = Some(SendCell::new(adj)); + *guard = Some(Fragile::new(adj)); info!("Saved episodes_view alignment."); }