diff --git a/Sources/Lichtkasten/Services/AppState.swift b/Sources/Lichtkasten/Services/AppState.swift index c9dd395..65d435e 100644 --- a/Sources/Lichtkasten/Services/AppState.swift +++ b/Sources/Lichtkasten/Services/AppState.swift @@ -515,13 +515,17 @@ final class AppState: ObservableObject { } } }, + onSequence: { [weak self] next in + // runs on success, cancel and error – the numbering never starts over + Task { @MainActor [weak self] in self?.settings.ingest.startSequence = next } + }, progress: { [weak self] p in Task { @MainActor [weak self] in self?.tasks.update(taskID, done: p.done, total: p.total, detail: p.currentFile) } }) // PM: the sequence continues with the next number next time. - if settings.sequenceEnabled { self.settings.ingest.startSequence = result.nextSequence } + if settings.sequenceEnabled { self.settings.ingest.startSequence = max(self.settings.ingest.startSequence, result.nextSequence) } // Eject right after copying – everything after this works on the copies only. var ejectNote = "" diff --git a/Sources/LichtkastenCore/Ingest/IngestService.swift b/Sources/LichtkastenCore/Ingest/IngestService.swift index 0489142..ee93d08 100644 --- a/Sources/LichtkastenCore/Ingest/IngestService.swift +++ b/Sources/LichtkastenCore/Ingest/IngestService.swift @@ -142,6 +142,7 @@ public enum IngestService { /// Copies the photos (and their XMP sidecars) from `sources` like PM's Ingest. public static func run(sources: [URL], settings: IngestSettings, exiftool: ExifTool, onFolder: (@Sendable (URL) -> Void)? = nil, + onSequence: (@Sendable (Int) -> Void)? = nil, progress: @escaping @Sendable (IngestProgress) -> Void) async throws -> IngestResult { let fm = FileManager.default guard !settings.primaryDestination.isEmpty else { throw UploadError.failed("Kein Ziel für den Ingest gewählt.") } @@ -194,7 +195,11 @@ public enum IngestService { progress(IngestProgress(done: 0, total: total, currentFile: "Starte …")) // also after a cancel/error: what was copied is not copied again next time - defer { if settings.incremental { saveHistory(history) } } + // also after a cancel/error the next number is handed back, so the next ingest continues there + defer { + if settings.incremental { saveHistory(history) } + if settings.sequenceEnabled { onSequence?(seq) } + } for e in entries { try Task.checkCancellation() let item = e.item