fix: always refresh NAS dir count, show connection status, fix screenshot filter reactivity

- buildManifestIndex now always scans the NAS directory on every full reconcile
  (removed the `totalCount <= 1` guard) so NAS Archive count updates accurately
  on every manual refresh, not just when the manifest is new/sparse
- The dir > manifest check still switches to filename-based matching when the
  directory has more files than Kisani's manifest (uploaded by other tools)
- checkStatusRow shows NAS connection status (orange dot + "NAS Connected" /
  red dot + "NAS Offline") below the timestamp line
- BackupFilter now conforms to Equatable; BackupView re-reconciles immediately
  when the screenshot/video/RAW filter toggles change

Co-Authored-By: Kutesir <kutesir@provoc.ug>
Co-Authored-By: Sentry <sentry@provoc.ug>
This commit is contained in:
Robin Kutesa
2026-05-18 23:15:51 +03:00
parent 78a6b377f2
commit 6c38893374
3 changed files with 74 additions and 47 deletions

View File

@@ -308,25 +308,26 @@ final class BackupStatusService: NSObject, ObservableObject {
lastManifest = manifest
Task { await NASManifestCache.shared.update(manifest) }
// Validity check: if the manifest has 1 entries it may be corrupt or newly
// created. Scan the directory to get the real NAS contents. When the directory
// is larger than the manifest, return a filename-based index so countSafe
// matches against the actual NAS files, not just the sparse manifest entries.
if index.totalCount <= 1 {
let items = (try? await Self.withTimeout(12) { try await transfer.listDirectory(at: conn.remotePath) }) ?? []
let filteredItems = items.filter {
!$0.isDirectory && !$0.name.hasPrefix(".") && $0.name != BackupManifest.remoteFilename
}
let dirCount = filteredItems.count
log.info("buildManifestIndex: validity — manifest=\(index.totalCount) dir=\(dirCount) — filename matching")
if dirCount > index.totalCount {
await NASManifestCache.shared.setDirectoryFilenames(filteredItems.map { $0.name })
return await Task.detached(priority: .utility) {
ManifestIndex(nasListing: items)
}.value
}
// Always scan directory so the NAS Archive count is accurate on every
// full reconcile (not just when the manifest is new/sparse).
// When the directory has more files than the manifest (uploaded by other
// tools), switch to filename-based matching so countSafe reflects real
// NAS coverage instead of only Kisani-tracked files.
let items = (try? await Self.withTimeout(12) { try await transfer.listDirectory(at: conn.remotePath) }) ?? []
let filteredItems = items.filter {
!$0.isDirectory && !$0.name.hasPrefix(".") && $0.name != BackupManifest.remoteFilename
}
let dirCount = filteredItems.count
log.info("buildManifestIndex: dir=\(dirCount) manifest=\(index.totalCount)")
if dirCount > index.totalCount {
await NASManifestCache.shared.setDirectoryFilenames(filteredItems.map { $0.name })
return await Task.detached(priority: .utility) {
ManifestIndex(nasListing: items)
}.value
} else {
await NASManifestCache.shared.setDirectoryCount(dirCount)
return index
}
return index
}
log.warning("buildManifestIndex: manifest downloaded but failed to decode (\(data.count) bytes)")
} catch {