VMWizardOSView.swift 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // Copyright © 2021 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 SwiftUI
  17. struct VMWizardOSView: View {
  18. @ObservedObject var wizardState: VMWizardState
  19. var body: some View {
  20. VMWizardContent("Operating System") {
  21. Section {
  22. #if os(macOS) && arch(arm64)
  23. if #available(macOS 12, *), wizardState.useVirtualization {
  24. Button {
  25. wizardState.operatingSystem = .macOS
  26. wizardState.useAppleVirtualization = true
  27. wizardState.isGuestToolsInstallRequested = false
  28. wizardState.legacyHardware = false
  29. wizardState.next()
  30. } label: {
  31. OperatingSystem(imageName: "mac", name: "macOS 12+")
  32. }
  33. }
  34. #endif
  35. if !wizardState.useVirtualization {
  36. Button {
  37. wizardState.operatingSystem = .ClassicMacOS
  38. wizardState.useAppleVirtualization = false
  39. wizardState.isGuestToolsInstallRequested = false
  40. wizardState.legacyHardware = true
  41. wizardState.next()
  42. } label: {
  43. OperatingSystem(imageName: "macos", name: "Classic Mac OS")
  44. }
  45. }
  46. Button {
  47. wizardState.operatingSystem = .Windows
  48. wizardState.useAppleVirtualization = false
  49. wizardState.isGuestToolsInstallRequested = true
  50. wizardState.legacyHardware = false
  51. wizardState.next()
  52. } label: {
  53. OperatingSystem(imageName: "windows", name: "Windows")
  54. }
  55. Button {
  56. wizardState.operatingSystem = .Linux
  57. wizardState.isGuestToolsInstallRequested = false
  58. wizardState.legacyHardware = false
  59. wizardState.next()
  60. } label: {
  61. OperatingSystem(imageName: "linux", name: "Linux")
  62. }
  63. } header: {
  64. Text("Preconfigured")
  65. }
  66. Section {
  67. Button {
  68. wizardState.operatingSystem = .Other
  69. wizardState.useAppleVirtualization = false
  70. wizardState.isGuestToolsInstallRequested = false
  71. wizardState.next()
  72. } label: {
  73. HStack {
  74. Image(systemName: "gearshape")
  75. .resizable()
  76. .frame(width: 30.0, height: 30.0)
  77. .aspectRatio(contentMode: .fit)
  78. Text("Other")
  79. .font(.title)
  80. }
  81. .padding()
  82. }
  83. } header: {
  84. Text("Custom")
  85. }
  86. }
  87. .buttonStyle(.inList)
  88. }
  89. }
  90. struct OperatingSystem: View {
  91. let imageName: String
  92. let name: LocalizedStringKey
  93. private var imageURL: URL {
  94. let path = Bundle.main.path(forResource: imageName, ofType: "png", inDirectory: "Icons")!
  95. return URL(fileURLWithPath: path)
  96. }
  97. #if os(macOS)
  98. private var icon: Image {
  99. Image(nsImage: NSImage(byReferencing: imageURL))
  100. }
  101. #else
  102. private var icon: Image {
  103. Image(uiImage: UIImage(contentsOfURL: imageURL)!)
  104. }
  105. #endif
  106. var body: some View {
  107. HStack {
  108. icon
  109. .resizable()
  110. .frame(width: 30.0, height: 30.0)
  111. .aspectRatio(contentMode: .fit)
  112. Text(name)
  113. .font(.title)
  114. }
  115. .padding()
  116. }
  117. }
  118. struct VMWizardOSView_Previews: PreviewProvider {
  119. @StateObject static var wizardState = VMWizardState()
  120. static var previews: some View {
  121. VMWizardOSView(wizardState: wizardState)
  122. }
  123. }