// A spoken command's answer, carried out by the shell: a record that// resolved opens where a tap would open it; words that named none open the// deck's Find with them, the same search the ink feeds.importCottonKitimportCottonVoiceimportFoundationimportSwiftUI@MainActorpublicenumVoiceCommands {/// Posted with `userInfo["query"]`: the deck shown opens Find with it.publicstaticlet search = Notification.Name("cotton.voice.search")/// `search`: where the command was said holds a search of its own/// (Home's, `voiceSearch`); without one the deck shown opens Find.publicstaticfunc run(_ command: VoiceCommand, navigator: Navigator?, search: (@MainActor (String) -> Void)? = nil) {if command.kind == "open", let table = command.table, let id = command.id { navigator?.open(table: table, id: id, definition: nil)return }guard !command.query.isEmpty else { return }iflet search { return search(command.query) }NotificationCenter.default.post(name: Self.search, object: nil, userInfo: ["query": command.query]) }}/// Home's search, handed to the fan Home draws: a spoken `search` command/// said there opens it with the words. Nil under a deck's fan.privatestructVoiceSearchKey: EnvironmentKey {staticlet defaultValue: (@MainActor (String) -> Void)? = nil}extensionEnvironmentValues {var voiceSearch: (@MainActor (String) -> Void)? { get { self[VoiceSearchKey.self] } set { self[VoiceSearchKey.self] = newValue } }}