From 243d5f47029c5e39a3fe1e16b6975c4c0c47d22c Mon Sep 17 00:00:00 2001 From: nyx Date: Wed, 16 Oct 2024 21:18:22 -0400 Subject: [PATCH] more optimization --- src/gui.rs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/gui.rs b/src/gui.rs index dfc4d5d..20b9d53 100644 --- a/src/gui.rs +++ b/src/gui.rs @@ -1,5 +1,5 @@ use gtk::{ - gio, prelude::*, Application, ApplicationWindow, Button, FlowBox, Image, ScrolledWindow, + gio, glib, prelude::*, Application, ApplicationWindow, Button, FlowBox, Image, ScrolledWindow, }; use shellexpand; use std::cell::RefCell; @@ -79,9 +79,18 @@ pub fn build_ui(app: &Application) { window.set_child(Some(&main_box)); - if let Some(last_path) = load_last_path() { - load_images(&last_path, &flowbox_ref, &cache); - } + let flowbox_clone = Rc::clone(&flowbox_ref); + let cache_clone = Arc::clone(&cache); + window.connect_show(move |_| { + if let Some(last_path) = load_last_path() { + let flowbox_clone2 = Rc::clone(&flowbox_clone); + let cache_clone2 = Arc::clone(&cache_clone); + glib::idle_add_local(move || { + load_images(&last_path, &flowbox_clone2, &cache_clone2); + glib::ControlFlow::Continue + }); + } + }); window.present(); } @@ -121,7 +130,7 @@ fn choose_folder( } fn load_images(folder: &PathBuf, flowbox: &Rc>, cache: &Arc>) { - let mut flowbox = flowbox.borrow_mut(); + let flowbox = flowbox.borrow_mut(); while let Some(child) = flowbox.first_child() { flowbox.remove(&child); }