Trigger a UI refresh when the scanner finds changes.

Closes #1025
This commit is contained in:
Deluan 2021-06-09 21:02:20 -04:00
parent cb6aa49439
commit 7f85ecd515
14 changed files with 110 additions and 41 deletions

View file

@ -35,7 +35,8 @@ var (
)
type FolderScanner interface {
Scan(ctx context.Context, lastModifiedSince time.Time, progress chan uint32) error
// Scan process finds any changes after `lastModifiedSince` and returns the number of changes found
Scan(ctx context.Context, lastModifiedSince time.Time, progress chan uint32) (int64, error)
}
var isScanning utils.AtomicBool
@ -89,11 +90,17 @@ func (s *scanner) rescan(ctx context.Context, mediaFolder string, fullRescan boo
progress, cancel := s.startProgressTracker(mediaFolder)
defer cancel()
err := folderScanner.Scan(ctx, lastModifiedSince, progress)
changeCount, err := folderScanner.Scan(ctx, lastModifiedSince, progress)
if err != nil {
log.Error("Error importing MediaFolder", "folder", mediaFolder, err)
}
if changeCount > 0 {
log.Debug(ctx, "Detected changes in the music folder. Sending refresh event",
"folder", mediaFolder, "changeCount", changeCount)
s.broker.SendMessage(&events.RefreshResource{})
}
s.updateLastModifiedSince(mediaFolder, start)
return err
}