Cotton code
33 lines · 1.2 KB · SwiftRaw
// An album's Find details on the phone (`find_details`): the lookups// (`AlbumLookup`), what they came to said in the music set's words.import CottonKitimport Foundation@MainActorfinal class MusicLookup {    static let shared = MusicLookup()    private var lookup: AlbumLookup?    private var say: ((String) -> Void)?    private var tell: ((String) -> Void)?    /// The core and the toasts, from the root once a core is open.    func attach(core: any CottonCalling, say: @escaping (String) -> Void, tell: @escaping (String) -> Void) {        lookup = AlbumLookup(core: core)        self.say = say        self.tell = tell    }    func findDetails(table: String, id: String) async {        guard let lookup, table == "music_album" else { return }        tell?(ShellLines.line("music", "lookup.looking", ["name": await lookup.name(of: id)]))        do {            let found = try await lookup.findDetails(album: id)            let name = ["name": found.name]            tell?(ShellLines.line("music", found.filled.isEmpty ? "lookup.nothing" : "lookup.filled", name))        } catch {            say?((error as? CottonCallError)?.message ?? ShellLines.line("music", "lookup.failed"))        }    }}