App: Fix more refference cycles
This commit is contained in:
parent
dae064d2bb
commit
5699562133
@ -1,8 +1,8 @@
|
|||||||
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#![cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
|
|
||||||
use gdk::FrameClockExt;
|
use gdk::FrameClockExt;
|
||||||
use gdk_pixbuf::Pixbuf;
|
use gdk_pixbuf::{Object, Pixbuf};
|
||||||
use glib;
|
use glib::{self, object::WeakRef};
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::{IsA, Widget};
|
use gtk::{IsA, Widget};
|
||||||
@ -64,16 +64,26 @@ use i18n::i18n;
|
|||||||
/// let list = gtk::ListBox::new();
|
/// let list = gtk::ListBox::new();
|
||||||
/// lazy_load(widgets, list, |w| w, || {});
|
/// lazy_load(widgets, list, |w| w, || {});
|
||||||
/// ```
|
/// ```
|
||||||
pub(crate) fn lazy_load<T, C, F, W, U>(data: T, container: C, mut contructor: F, callback: U)
|
pub(crate) fn lazy_load<T, C, F, W, U>(
|
||||||
where
|
data: T,
|
||||||
|
container: WeakRef<C>,
|
||||||
|
mut contructor: F,
|
||||||
|
callback: U,
|
||||||
|
) where
|
||||||
T: IntoIterator + 'static,
|
T: IntoIterator + 'static,
|
||||||
T::Item: 'static,
|
T::Item: 'static,
|
||||||
C: ContainerExt + 'static,
|
// FIXME: leaking a strong refference here
|
||||||
|
C: IsA<Object> + ContainerExt + 'static,
|
||||||
F: FnMut(T::Item) -> W + 'static,
|
F: FnMut(T::Item) -> W + 'static,
|
||||||
W: IsA<Widget> + WidgetExt,
|
W: IsA<Widget> + WidgetExt,
|
||||||
U: Fn() + 'static,
|
U: Fn() + 'static,
|
||||||
{
|
{
|
||||||
let func = move |x| {
|
let func = move |x| {
|
||||||
|
let container = match container.upgrade() {
|
||||||
|
Some(c) => c,
|
||||||
|
None => return,
|
||||||
|
};
|
||||||
|
|
||||||
let widget = contructor(x);
|
let widget = contructor(x);
|
||||||
container.add(&widget);
|
container.add(&widget);
|
||||||
widget.show();
|
widget.show();
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use glib;
|
use glib;
|
||||||
use gtk::{self, prelude::*, Adjustment};
|
use gtk::{self, prelude::*, Adjustment};
|
||||||
|
|
||||||
use crossbeam_channel::Sender;
|
use crossbeam_channel::{bounded, Sender};
|
||||||
use failure::Error;
|
use failure::Error;
|
||||||
use fragile::Fragile;
|
use fragile::Fragile;
|
||||||
use html2text;
|
use html2text;
|
||||||
@ -103,14 +103,11 @@ impl ShowWidget {
|
|||||||
|
|
||||||
/// Populate the listbox with the shows episodes.
|
/// Populate the listbox with the shows episodes.
|
||||||
fn populate_listbox(
|
fn populate_listbox(
|
||||||
// FIXME: we are leaking strong refs here
|
|
||||||
show: &Rc<ShowWidget>,
|
show: &Rc<ShowWidget>,
|
||||||
pd: Arc<Show>,
|
pd: Arc<Show>,
|
||||||
sender: Sender<Action>,
|
sender: Sender<Action>,
|
||||||
vadj: Option<Adjustment>,
|
vadj: Option<Adjustment>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
use crossbeam_channel::bounded;
|
|
||||||
|
|
||||||
let count = dbqueries::get_pd_episodes_count(&pd)?;
|
let count = dbqueries::get_pd_episodes_count(&pd)?;
|
||||||
|
|
||||||
let (sender_, receiver) = bounded(1);
|
let (sender_, receiver) = bounded(1);
|
||||||
@ -128,7 +125,8 @@ fn populate_listbox(
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let show_ = show.clone();
|
let show_weak = Rc::downgrade(&show);
|
||||||
|
let list_weak = show.episodes.downgrade();
|
||||||
gtk::idle_add(move || {
|
gtk::idle_add(move || {
|
||||||
let episodes = match receiver.try_recv() {
|
let episodes = match receiver.try_recv() {
|
||||||
Some(e) => e,
|
Some(e) => e,
|
||||||
@ -136,18 +134,18 @@ fn populate_listbox(
|
|||||||
};
|
};
|
||||||
debug_assert!(episodes.len() as i64 == count);
|
debug_assert!(episodes.len() as i64 == count);
|
||||||
|
|
||||||
let list = show_.episodes.clone();
|
|
||||||
let constructor = clone!(sender => move |ep| {
|
let constructor = clone!(sender => move |ep| {
|
||||||
EpisodeWidget::new(ep, &sender).container.clone()
|
EpisodeWidget::new(ep, &sender).container.clone()
|
||||||
});
|
});
|
||||||
|
|
||||||
let callback = clone!(show_, vadj => move || {
|
let callback = clone!(show_weak, vadj => move || {
|
||||||
if let Some(ref v) = vadj {
|
match (show_weak.upgrade(), &vadj) {
|
||||||
show_.view.set_adjutments(None, Some(v))
|
(Some(ref shows), Some(ref v)) => shows.view.set_adjutments(None, Some(v)),
|
||||||
|
_ => (),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
lazy_load(episodes, list.clone(), constructor, callback);
|
lazy_load(episodes, list_weak.clone(), constructor, callback);
|
||||||
|
|
||||||
glib::Continue(false)
|
glib::Continue(false)
|
||||||
});
|
});
|
||||||
|
|||||||
@ -64,17 +64,18 @@ impl ShowsView {
|
|||||||
fn populate_flowbox(shows: &Rc<ShowsView>, vadj: Option<Adjustment>) -> Result<(), Error> {
|
fn populate_flowbox(shows: &Rc<ShowsView>, vadj: Option<Adjustment>) -> Result<(), Error> {
|
||||||
let ignore = get_ignored_shows()?;
|
let ignore = get_ignored_shows()?;
|
||||||
let podcasts = dbqueries::get_podcasts_filter(&ignore)?;
|
let podcasts = dbqueries::get_podcasts_filter(&ignore)?;
|
||||||
|
let show_weak = Rc::downgrade(&shows);
|
||||||
|
let flowbox_weak = shows.flowbox.downgrade();
|
||||||
|
|
||||||
let constructor = move |parent| ShowsChild::new(&parent).child;
|
let constructor = move |parent| ShowsChild::new(&parent).child;
|
||||||
// FIXME: We are, possibly,leaking the strong ref here
|
let callback = move || {
|
||||||
let callback = clone!(shows => move || {
|
match (show_weak.upgrade(), &vadj) {
|
||||||
if let Some(ref v) = vadj {
|
(Some(ref shows), Some(ref v)) => shows.view.set_adjutments(None, Some(v)),
|
||||||
shows.view.set_adjutments(None, Some(v))
|
_ => (),
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
let flowbox = shows.flowbox.clone();
|
lazy_load(podcasts, flowbox_weak, constructor, callback);
|
||||||
lazy_load(podcasts, flowbox, constructor, callback);
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user