// How far a films' intake has got, for the deck's top line ("Reading 12// files", then "41 of 212"): a folder of a series brings hundreds of files in// at once, and the deck says so while they come, then goes back to its own// count. As Music's (`MusicIntakeProgress`).importCottonValuesimportFoundationimportObservation@MainActor @ObservablepublicfinalclassFilmIntakeProgress {public nonisolated staticlet shared = FilmIntakeProgress()/// Made off the main actor: the share drain says how far it has got from/// wherever it runs. nonisolated init() {}/// Files brought in, of all of them, and whether the first of them are/// still being read; nil when nothing is coming in.publicprivate(set) var counted: (done: Int, total: Int, reading: Bool)?/// The tables whose decks say it: the films and what they gather into.publicstaticlet tables: Set<String> = ["film", "film_season", "film_episode"]/// Said from any thread: the deck reads it on the main one.public nonisolated func say(_ done: Int, of total: Int, reading: Bool) {Task { @MainActor inself.counted = done >= total ? nil : (done, total, reading) } }/// Nothing is coming in any more.public nonisolated func done() {Task { @MainActor inself.counted = nil } }/// The deck's top line while films come in; nil when none do.publicfunc line(table: String) -> String? {guardlet counted, Self.tables.contains(table) else { returnnil }returnSelf.line(counted.done, of: counted.total, reading: counted.reading) }/// "Reading 12 files" before the first is in, then "41 of 212".public nonisolated staticfunc line(_ done: Int, of total: Int, reading: Bool) -> String {if reading, done == 0 { returnShellLines.line("cinemas", "intake.reading", ["count": String(total)]) }returnShellLines.line("cinemas", "intake.progress", ["done": String(done), "total": String(total)]) }}