From de7485598ab65d0583a28e44094deb6bf211a9b0 Mon Sep 17 00:00:00 2001 From: David Bliss Date: Sun, 7 Apr 2024 16:19:23 +0100 Subject: [PATCH] Code cleanup --- src/app.rs | 7 ++-- src/app/background/generate_previews.rs | 8 +++-- src/app/background/scan_photos.rs | 4 +-- src/app/components/album.rs | 43 ------------------------- 4 files changed, 9 insertions(+), 53 deletions(-) diff --git a/src/app.rs b/src/app.rs index 12455342..570d7497 100644 --- a/src/app.rs +++ b/src/app.rs @@ -414,9 +414,6 @@ impl SimpleComponent for App { let repo = Arc::new(Mutex::new(repo)); - //let controller = photos_core::Controller::new(scan.clone(), repo, previewer); - //let controller = Arc::new(Mutex::new(controller)); - let scan_photos = ScanPhotos::builder() .detach_worker((scan.clone(), repo.clone())) .forward(sender.input_sender(), |msg| match msg { @@ -552,7 +549,7 @@ impl SimpleComponent for App { model.all_photos.emit(AlbumInput::Refresh); - model.scan_photos.sender().emit(ScanPhotosInput::ScanAll); + model.scan_photos.sender().emit(ScanPhotosInput::Start); // model.selfie_photos.emit(SelfiePhotosInput::Refresh); // model.month_photos.emit(MonthPhotosInput::Refresh); // model.year_photos.emit(YearPhotosInput::Refresh); @@ -636,7 +633,7 @@ impl SimpleComponent for App { self.month_photos.emit(MonthPhotosInput::Refresh); self.year_photos.emit(YearPhotosInput::Refresh); - self.generate_previews.emit(GeneratePreviewsInput::Generate); + self.generate_previews.emit(GeneratePreviewsInput::Start); }, AppMsg::ThumbnailGenerationStarted(count) => { println!("Thumbnail generation started."); diff --git a/src/app/background/generate_previews.rs b/src/app/background/generate_previews.rs index 77ac86bf..bd6aabdb 100644 --- a/src/app/background/generate_previews.rs +++ b/src/app/background/generate_previews.rs @@ -10,7 +10,7 @@ use rayon::prelude::*; #[derive(Debug)] pub enum GeneratePreviewsInput { - Generate, + Start, } #[derive(Debug)] @@ -47,7 +47,9 @@ impl GeneratePreviews { .collect(); let pics_count = pics.len(); - sender.output(GeneratePreviewsOutput::Started(pics_count)); + if let Err(e) = sender.output(GeneratePreviewsOutput::Started(pics_count)){ + println!("Failed sending gen started: {:?}", e); + } // Process newer photos first. pics.reverse(); @@ -89,7 +91,7 @@ impl Worker for GeneratePreviews { fn update(&mut self, msg: GeneratePreviewsInput, sender: ComponentSender) { match msg { - GeneratePreviewsInput::Generate => { + GeneratePreviewsInput::Start => { println!("Generating previews..."); if let Err(e) = self.update_previews(&sender) { diff --git a/src/app/background/scan_photos.rs b/src/app/background/scan_photos.rs index 4fa295b5..6e75b87d 100644 --- a/src/app/background/scan_photos.rs +++ b/src/app/background/scan_photos.rs @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex}; #[derive(Debug)] pub enum ScanPhotosInput { - ScanAll, + Start, } #[derive(Debug)] @@ -33,7 +33,7 @@ impl Worker for ScanPhotos { fn update(&mut self, msg: ScanPhotosInput, sender: ComponentSender) { match msg { - ScanPhotosInput::ScanAll => { + ScanPhotosInput::Start => { let result = self.scan_and_add(sender); if let Err(e) = result { println!("Failed scan with: {}", e); diff --git a/src/app/components/album.rs b/src/app/components/album.rs index db778cd8..2ea8def4 100644 --- a/src/app/components/album.rs +++ b/src/app/components/album.rs @@ -41,9 +41,6 @@ pub enum AlbumInput { // Scroll to first photo of year/month. GoToMonth(YearMonth), - // Preview has been updated - PreviewUpdated(PictureId, Option), - // Reload photos from database Refresh, @@ -196,46 +193,6 @@ impl SimpleAsyncComponent for Album { self.photo_grid.view.scroll_to(index, flags, None); } }, - AlbumInput::PreviewUpdated(id, path) => { - // This doesn't really work properly. - // The intent was to have updated thumbnails be immediately visible, but I've - // never been able to make this work in a was that is fast and delightful. - // If the grid item thumbnail path is updated, then the item isn't refreshed - // visually so the thumbnail isn't visible until there is a mouseover event, which - // makes the app seem like it isn't working correctly. - // I've tried triggering a refresh with adding and removing items, and with - // disabling and enabling filters, but both have problems. Adding and removing - // items is slow and seems to get slower as more previews are generated. - // Disabling and enabling filters looked promising, but causing a lot of jumping - // around and also resulted in a large slowdown that prompted "Force Quit" dialogs - // to pop up. - // - // So, for now this code is unused and will have to be removed if a decent - // working solution can't be found. -/* - println!("Preview updated "); - - if self.photo_grid.is_empty() { - // WARN calling find() on an empty grid causes a crash without - // a stack trace :-/ - return; - } - - let Some(index) = self.photo_grid.find(|p| p.picture.picture_id == id) else { - println!("No index for picture id: {}", id); - return; - }; - - let Some(item) = self.photo_grid.get(index) else { - return; - }; - - { - let mut item = item.borrow_mut(); - item.picture.square_preview_path = path; - } - */ - }, } } }