Skip to content

Commit

Permalink
fix(FileBrowser): use Rc::downgrade to avoid a circular Rc reference …
Browse files Browse the repository at this point in the history
…that prevents the callback from ever being dropped
  • Loading branch information
lautarodragan committed Feb 3, 2025
1 parent 2b69115 commit 0efa64a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ fn run_sync(mpris: Mpris) -> Result<(), Box<dyn Error>> {
log::error!("Could not save app state {err:?}");
}

log::trace!("Dropping root_component...");
drop(root_component);
log::trace!("root_component dropped");

log::debug!(
"main_player strong_count: {}. weak_count: {}",
Expand Down
6 changes: 5 additions & 1 deletion src/components/file_browser/file_browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,16 @@ impl<'a> FileBrowser<'a> {
parents_list.on_confirm({
let on_enqueue_fn = Rc::clone(&on_enqueue_fn);
let current_directory = Rc::clone(&current_directory);
let parents_list = Rc::clone(&parents_list);
let parents_list = Rc::downgrade(&parents_list);
let children_list = children_list.clone();
let history = Rc::clone(&history);

move |item| match item {
FileBrowserSelection::Directory(path) => {
let Some(parents_list) = parents_list.upgrade() else {
return;
};

let files = directory_to_songs_and_folders(path.as_path());

if !files.iter().any(|f| matches!(f, FileBrowserSelection::Directory(_))) {
Expand Down

0 comments on commit 0efa64a

Please sign in to comment.