Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
blissd committed Apr 7, 2024
1 parent 92f48be commit de74855
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 53 deletions.
7 changes: 2 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
Expand Down
8 changes: 5 additions & 3 deletions src/app/background/generate_previews.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rayon::prelude::*;

#[derive(Debug)]
pub enum GeneratePreviewsInput {
Generate,
Start,
}

#[derive(Debug)]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -89,7 +91,7 @@ impl Worker for GeneratePreviews {

fn update(&mut self, msg: GeneratePreviewsInput, sender: ComponentSender<Self>) {
match msg {
GeneratePreviewsInput::Generate => {
GeneratePreviewsInput::Start => {
println!("Generating previews...");

if let Err(e) = self.update_previews(&sender) {
Expand Down
4 changes: 2 additions & 2 deletions src/app/background/scan_photos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::sync::{Arc, Mutex};

#[derive(Debug)]
pub enum ScanPhotosInput {
ScanAll,
Start,
}

#[derive(Debug)]
Expand All @@ -33,7 +33,7 @@ impl Worker for ScanPhotos {

fn update(&mut self, msg: ScanPhotosInput, sender: ComponentSender<Self>) {
match msg {
ScanPhotosInput::ScanAll => {
ScanPhotosInput::Start => {
let result = self.scan_and_add(sender);
if let Err(e) = result {
println!("Failed scan with: {}", e);
Expand Down
43 changes: 0 additions & 43 deletions src/app/components/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ pub enum AlbumInput {
// Scroll to first photo of year/month.
GoToMonth(YearMonth),

// Preview has been updated
PreviewUpdated(PictureId, Option<PathBuf>),

// Reload photos from database
Refresh,

Expand Down Expand Up @@ -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;
}
*/
},
}
}
}
Expand Down

0 comments on commit de74855

Please sign in to comment.