diff --git a/Cargo.lock b/Cargo.lock index babf1b9..8253ae9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,15 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "crossbeam-channel" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.5" @@ -660,6 +669,7 @@ checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" name = "hyprwall" version = "0.1.1" dependencies = [ + "crossbeam-channel", "gdk", "gio 0.18.4", "glib 0.18.5", diff --git a/Cargo.toml b/Cargo.toml index f033e4d..29c4a00 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ parking_lot = "0.12.1" rayon = "1.7" num_cpus = "1.15" rand = "0.8" +crossbeam-channel = "0.5" [profile.release] lto = true diff --git a/src/gui.rs b/src/gui.rs index 48bb006..48041dc 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,3 +1,4 @@ +use crossbeam_channel::unbounded; use glib::ControlFlow; use gtk::gdk::Texture; use gtk::gdk_pixbuf::Pixbuf; @@ -15,8 +16,8 @@ use std::{ io::Read, path::{Path, PathBuf}, rc::Rc, - sync::{mpsc, Arc}, sync::atomic::{AtomicBool, Ordering}, + sync::Arc, }; const CONFIG_FILE: &str = "~/.config/hyprwall/config.ini"; @@ -242,7 +243,7 @@ fn load_images( let cache = Arc::clone(&image_loader.cache); let flowbox_clone = Rc::clone(flowbox); - let (sender, receiver) = mpsc::channel::<(Texture, String)>(); + let (sender, receiver) = unbounded::<(Texture, String)>(); while let Some(child) = flowbox.borrow().first_child() { flowbox.borrow().remove(&child); @@ -272,8 +273,9 @@ fn load_images( }; let path_clone = path.to_str().unwrap_or("").to_string(); - s.send((texture, path_clone)) - .expect("Failed to send texture"); + if s.send((texture, path_clone)).is_err() { + eprintln!("Failed to send texture: receiver disconnected"); + } }); }); @@ -314,8 +316,8 @@ fn load_images( flowbox.insert(&button, -1); } - Err(mpsc::TryRecvError::Empty) => break, - Err(mpsc::TryRecvError::Disconnected) => return ControlFlow::Break, + Err(crossbeam_channel::TryRecvError::Empty) => break, + Err(crossbeam_channel::TryRecvError::Disconnected) => return ControlFlow::Break, } } ControlFlow::Continue