TempPresetIntent.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import AppIntents
  2. import Foundation
  3. import Intents
  4. import Swinject
  5. @available(iOS 16.0, *) struct TempPreset: AppEntity, Identifiable {
  6. static var defaultQuery = TempPresetsQuery()
  7. var id: UUID
  8. var name: String
  9. var targetTop: Decimal?
  10. var targetBottom: Decimal?
  11. var duration: Decimal
  12. var displayRepresentation: DisplayRepresentation {
  13. DisplayRepresentation(title: "\(name)")
  14. }
  15. static var typeDisplayRepresentation: TypeDisplayRepresentation = "Presets"
  16. // static func convert(_ tempTarget: TempTarget) -> TempPreset {
  17. // var tp = TempPreset(
  18. // id: UUID(uuidString: tempTarget.id)!,
  19. // name: tempTarget.displayName,
  20. // duration: tempTarget.duration
  21. // )
  22. // tp.targetTop = tempTarget.targetTop
  23. // tp.targetBottom = tempTarget.targetBottom
  24. // return tp
  25. // }
  26. }
  27. struct TempPresetsQuery: EntityQuery {
  28. internal var intentRequest: TempPresetsIntentRequest
  29. init() {
  30. intentRequest = TempPresetsIntentRequest()
  31. }
  32. func entities(for identifiers: [TempPreset.ID]) async throws -> [TempPreset] {
  33. await intentRequest.fetchIDs(identifiers)
  34. }
  35. func suggestedEntities() async throws -> [TempPreset] {
  36. await intentRequest.fetchAndProcessTempTargets()
  37. }
  38. }