@@ -466,7 +466,9 @@ const SingleFileTab = ({ filePath, setFilePath, selectedAlgorithms, handleAlgori
466466 applyHashResults ( mergedResults ) ;
467467 } catch ( error ) {
468468 console . error ( 'Hash calculation failed:' , error ) ;
469- showAlert ( 'Error' , 'Hash calculation failed: ' + error ) ;
469+ if ( error !== "Cancelled" ) {
470+ showAlert ( 'Error' , 'Hash calculation failed: ' + error ) ;
471+ }
470472 } finally {
471473 setIsHashing ( false ) ;
472474 setProgress ( null ) ;
@@ -482,11 +484,13 @@ const SingleFileTab = ({ filePath, setFilePath, selectedAlgorithms, handleAlgori
482484 ( async ( ) => {
483485 unlisten = await listen ( 'hash-progress' , ( event : any ) => {
484486 const payload = event . payload as any ;
485- setProgress ( {
486- percent : payload . percent || 0 ,
487- bytes_read : payload . bytes_read || 0 ,
488- total : payload . total || 0
489- } ) ;
487+ if ( payload . file === filePath ) {
488+ setProgress ( {
489+ percent : payload . percent || 0 ,
490+ bytes_read : payload . bytes_read || 0 ,
491+ total : payload . total || 0
492+ } ) ;
493+ }
490494 } ) ;
491495 } ) ( ) ;
492496
@@ -495,7 +499,7 @@ const SingleFileTab = ({ filePath, setFilePath, selectedAlgorithms, handleAlgori
495499 unlisten . then ( ( f : any ) => f ( ) ) ;
496500 }
497501 } ;
498- } , [ ] ) ;
502+ } , [ filePath ] ) ;
499503
500504 const handleSaveReport = async ( ) => {
501505 if ( ! filePath ) {
@@ -885,6 +889,7 @@ const FolderScanTab = ({ folderPath, setFolderPath, selectedAlgorithms, handleAl
885889 const [ files , setFiles ] = useState < any [ ] > ( [ ] ) ;
886890 const [ includeSubfolders , setIncludeSubfolders ] = useState ( true ) ;
887891 const [ includeHidden , setIncludeHidden ] = useState ( false ) ;
892+ const [ isScanning , setIsScanning ] = useState ( false ) ;
888893
889894 const handleFolderSelect = async ( ) => {
890895 const selected = await openDialog ( {
@@ -905,13 +910,21 @@ const FolderScanTab = ({ folderPath, setFolderPath, selectedAlgorithms, handleAl
905910 return ;
906911 }
907912
908- const scannedFiles = await invoke ( "scan_folder" , {
909- folderPath,
910- includeSubfolders,
911- includeHidden,
912- algorithms
913- } ) ;
914- setFiles ( scannedFiles as any [ ] ) ;
913+ setIsScanning ( true ) ;
914+ setFiles ( [ ] ) ;
915+ try {
916+ const scannedFiles = await invoke ( "scan_folder" , {
917+ folderPath,
918+ includeSubfolders,
919+ includeHidden,
920+ algorithms
921+ } ) ;
922+ setFiles ( scannedFiles as any [ ] ) ;
923+ } catch ( e ) {
924+ if ( e !== "Cancelled" ) showAlert ( 'Error' , `Folder scan failed: ${ e } ` ) ;
925+ } finally {
926+ setIsScanning ( false ) ;
927+ }
915928 } ;
916929
917930 const handleSaveReport = async ( ) => {
@@ -995,7 +1008,13 @@ const FolderScanTab = ({ folderPath, setFolderPath, selectedAlgorithms, handleAl
9951008 < FormControlLabel control = { < Checkbox checked = { includeHidden } onChange = { ( ) => setIncludeHidden ( ! includeHidden ) } /> } label = "Include Hidden Files" />
9961009 </ Box >
9971010
998- < Button variant = "contained" onClick = { handleScan } fullWidth sx = { { mt : 2 } } > Scan Folder</ Button >
1011+ < Box sx = { { mt : 2 , display : 'flex' , gap : 1 } } >
1012+ < Button variant = "contained" onClick = { handleScan } fullWidth disabled = { isScanning } > Scan Folder</ Button >
1013+ { isScanning && (
1014+ < Button variant = "outlined" color = "error" onClick = { ( ) => invoke ( 'cancel_hashing' ) } > Cancel</ Button >
1015+ ) }
1016+ </ Box >
1017+ { isScanning && < LinearProgress sx = { { mt : 2 } } /> }
9991018
10001019 < TableContainer component = { Paper } sx = { { mt : 2 } } >
10011020 < Table >
0 commit comments