@@ -16,6 +16,12 @@ const TESSERACT_PATH_ENV: &str = "FLASH_SHOT_TESSERACT";
1616const TESSERACT_LANGUAGE_ENV : & str = "FLASH_SHOT_OCR_LANGUAGE" ;
1717const OCR_COMMAND_TIMEOUT : Duration = Duration :: from_secs ( 20 ) ;
1818
19+ #[ cfg( windows) ]
20+ const WINDOWS_TESSERACT_PATHS : [ & str ; 2 ] = [
21+ r"C:\Program Files\Tesseract-OCR\tesseract.exe" ,
22+ r"C:\Program Files (x86)\Tesseract-OCR\tesseract.exe" ,
23+ ] ;
24+
1925/// Read-only local OCR readiness information used before the user begins a capture workflow.
2026#[ derive( Clone , Debug , Eq , PartialEq ) ]
2127pub struct OcrSupport {
@@ -144,8 +150,21 @@ fn wait_for_child(child: &mut Child, timeout: Duration) -> io::Result<()> {
144150 }
145151}
146152
153+ /// Selects an explicit executable override, common Windows install paths, or PATH lookup.
147154fn executable_path ( ) -> OsString {
148- std:: env:: var_os ( TESSERACT_PATH_ENV ) . unwrap_or_else ( || OsString :: from ( "tesseract" ) )
155+ if let Some ( configured) = std:: env:: var_os ( TESSERACT_PATH_ENV ) . filter ( |value| !value. is_empty ( ) )
156+ {
157+ return configured;
158+ }
159+ #[ cfg( windows) ]
160+ if let Some ( installed) = WINDOWS_TESSERACT_PATHS
161+ . iter ( )
162+ . map ( Path :: new)
163+ . find ( |path| path. is_file ( ) )
164+ {
165+ return installed. as_os_str ( ) . to_owned ( ) ;
166+ }
167+ OsString :: from ( "tesseract" )
149168}
150169
151170fn language ( ) -> String {
@@ -245,6 +264,18 @@ mod tests {
245264 assert_eq ! ( OCR_COMMAND_TIMEOUT , Duration :: from_secs( 20 ) ) ;
246265 }
247266
267+ #[ cfg( windows) ]
268+ #[ test]
269+ fn common_windows_tesseract_paths_are_absolute_and_executable_named ( ) {
270+ assert ! ( super :: WINDOWS_TESSERACT_PATHS . iter( ) . all( |path| {
271+ let path = Path :: new( path) ;
272+ path. is_absolute( )
273+ && path
274+ . file_name( )
275+ . is_some_and( |name| name. eq_ignore_ascii_case( "tesseract.exe" ) )
276+ } ) ) ;
277+ }
278+
248279 #[ test]
249280 fn completed_ocr_processes_are_reaped_before_the_deadline ( ) {
250281 let mut command = if cfg ! ( windows) {
0 commit comments