VMWizardOSView.swift 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.next()
  29. } label: {
  30. OperatingSystem(imageName: "Logo-macOS", name: "macOS 12+")
  31. }
  32. }
  33. #endif
  34. if !wizardState.useVirtualization {
  35. Button {
  36. wizardState.operatingSystem = .ClassicMacOS
  37. wizardState.useAppleVirtualization = false
  38. wizardState.isGuestToolsInstallRequested = false
  39. wizardState.next()
  40. } label: {
  41. OperatingSystem(imageName: "Logo-macOS", name: "Classic Mac OS")
  42. }
  43. }
  44. Button {
  45. wizardState.operatingSystem = .Windows
  46. wizardState.useAppleVirtualization = false
  47. wizardState.isGuestToolsInstallRequested = true
  48. wizardState.next()
  49. } label: {
  50. OperatingSystem(imageName: "Logo-Windows", name: "Windows")
  51. }
  52. Button {
  53. wizardState.operatingSystem = .Linux
  54. wizardState.isGuestToolsInstallRequested = false
  55. wizardState.next()
  56. } label: {
  57. OperatingSystem(imageName: "Logo-Linux", name: "Linux")
  58. }
  59. } header: {
  60. Text("Preconfigured")
  61. }
  62. Section {
  63. Button {
  64. wizardState.operatingSystem = .Other
  65. wizardState.useAppleVirtualization = false
  66. wizardState.isGuestToolsInstallRequested = false
  67. wizardState.next()
  68. } label: {
  69. HStack {
  70. Image(systemName: "gearshape")
  71. .resizable()
  72. .frame(width: 30.0, height: 30.0)
  73. .aspectRatio(contentMode: .fit)
  74. Text("Other")
  75. .font(.title)
  76. }
  77. .padding()
  78. }
  79. } header: {
  80. Text("Custom")
  81. }
  82. }
  83. .buttonStyle(.inList)
  84. }
  85. }
  86. struct OperatingSystem: View {
  87. let imageName: String
  88. let name: LocalizedStringKey
  89. #if os(macOS)
  90. private var icon: Image {
  91. Image(nsImage: NSImage(named: imageName)!)
  92. }
  93. #else
  94. private var icon: Image {
  95. Image(uiImage: UIImage(named: imageName)!)
  96. }
  97. #endif
  98. var body: some View {
  99. HStack {
  100. icon
  101. .resizable()
  102. .frame(width: 30.0, height: 30.0)
  103. .aspectRatio(contentMode: .fit)
  104. Text(name)
  105. .font(.title)
  106. }
  107. .padding()
  108. }
  109. }
  110. struct VMWizardOSView_Previews: PreviewProvider {
  111. @StateObject static var wizardState = VMWizardState()
  112. static var previews: some View {
  113. VMWizardOSView(wizardState: wizardState)
  114. }
  115. }