-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
83 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod scan_photos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use relm4::prelude::*; | ||
use relm4::Worker; | ||
|
||
#[derive(Debug)] | ||
pub enum ScanPhotosInput { | ||
ScanAll, | ||
} | ||
|
||
#[derive(Debug)] | ||
pub enum ScanPhotosOutput { | ||
ScanAllCompleted(Vec<photos_core::scanner::Picture>), | ||
} | ||
|
||
pub struct ScanPhotos { | ||
scanner: photos_core::Scanner, | ||
} | ||
|
||
impl Worker for ScanPhotos { | ||
type Init = photos_core::Scanner; | ||
type Input = ScanPhotosInput; | ||
type Output = ScanPhotosOutput; | ||
|
||
fn init(scanner: Self::Init, _sender: ComponentSender<Self>) -> Self { | ||
Self { scanner } | ||
} | ||
|
||
fn update(&mut self, msg: ScanPhotosInput, sender: ComponentSender<Self>) { | ||
match msg { | ||
ScanPhotosInput::ScanAll => { | ||
println!("ScanAll"); | ||
let start_at = std::time::SystemTime::now(); | ||
let result = self.scanner.scan_all(); | ||
let end_at = std::time::SystemTime::now(); | ||
|
||
if let Ok(pics) = result { | ||
let duration = end_at.duration_since(start_at).unwrap_or(std::time::Duration::new(0, 0)); | ||
println!("Scanned {} items in {} seconds", pics.len(), duration.as_secs()); | ||
let _ = sender.output(ScanPhotosOutput::ScanAllCompleted(pics)); | ||
} else { | ||
println!("Failed scanning: {:?}", result); | ||
} | ||
} | ||
}; | ||
} | ||
} |