UTMVirtualMachineEntity.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // Copyright © 2025 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. import AppIntents
  17. @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
  18. struct UTMVirtualMachineEntity: AppEntity {
  19. static let defaultQuery = UTMVirtualMachineEntityQuery()
  20. let id: UUID
  21. var iconURL: URL?
  22. @Property(title: "Name")
  23. var name: String
  24. @Property(title: "Description")
  25. var description: String
  26. @Property(title: "Status")
  27. var state: UTMVirtualMachineState
  28. static var typeDisplayRepresentation: TypeDisplayRepresentation {
  29. TypeDisplayRepresentation(
  30. name: "Virtual Machine",
  31. numericFormat: "\(placeholder: .int) virtual machines"
  32. )
  33. }
  34. var displayRepresentation: DisplayRepresentation {
  35. var display = DisplayRepresentation(
  36. title: "\(name)",
  37. subtitle: "\(description)"
  38. )
  39. if let iconURL = iconURL {
  40. display.image = DisplayRepresentation.Image(url: iconURL)
  41. }
  42. return display
  43. }
  44. @MainActor
  45. init(from vm: VMData) {
  46. id = vm.id
  47. name = vm.detailsTitleLabel
  48. description = vm.detailsSubtitleLabel
  49. state = vm.state
  50. iconURL = vm.detailsIconUrl
  51. }
  52. }
  53. @available(iOS 18, macOS 15, *)
  54. extension UTMVirtualMachineEntity: IndexedEntity {
  55. }
  56. @available(iOS 16, macOS 13, tvOS 16, watchOS 9, *)
  57. extension UTMVirtualMachineState: AppEnum {
  58. static let typeDisplayRepresentation: TypeDisplayRepresentation =
  59. TypeDisplayRepresentation(
  60. name: "Status"
  61. )
  62. static let caseDisplayRepresentations: [UTMVirtualMachineState: DisplayRepresentation] = [
  63. .stopped: DisplayRepresentation(title: "Stopped"),
  64. .starting: DisplayRepresentation(title: "Starting"),
  65. .started: DisplayRepresentation(title: "Started"),
  66. .pausing: DisplayRepresentation(title: "Pausing"),
  67. .paused: DisplayRepresentation(title: "Paused"),
  68. .resuming: DisplayRepresentation(title: "Resuming"),
  69. .saving: DisplayRepresentation(title: "Saving"),
  70. .restoring: DisplayRepresentation(title: "Restoring"),
  71. .stopping: DisplayRepresentation(title: "Stopping"),
  72. ]
  73. }