VMWizardOSWindowsView.swift 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 VMWizardOSWindowsView: View {
  18. @ObservedObject var wizardState: VMWizardState
  19. @State private var isFileImporterPresented: Bool = false
  20. var body: some View {
  21. VMWizardContent("Windows") {
  22. #if !WITH_QEMU_TCI
  23. Section {
  24. Toggle("Install Windows 10 or higher", isOn: $wizardState.isWindows10OrHigher)
  25. .onChange(of: wizardState.isWindows10OrHigher) { newValue in
  26. if newValue {
  27. wizardState.systemBootUefi = true
  28. wizardState.systemBootTpm = true
  29. wizardState.isGuestToolsInstallRequested = true
  30. } else {
  31. wizardState.systemBootUefi = false
  32. wizardState.systemBootTpm = false
  33. wizardState.isGuestToolsInstallRequested = false
  34. }
  35. }
  36. .disabled(wizardState.legacyHardware)
  37. if wizardState.isWindows10OrHigher {
  38. #if os(macOS)
  39. Button {
  40. let downloadCrystalFetch = URL(string: "https://mac.getutm.app/crystalfetch/")!
  41. if let crystalFetch = NSWorkspace.shared.urlForApplication(withBundleIdentifier: "llc.turing.CrystalFetch") {
  42. NSWorkspace.shared.openApplication(at: crystalFetch, configuration: .init()) { _, error in
  43. if error != nil {
  44. NSWorkspace.shared.open(downloadCrystalFetch)
  45. }
  46. }
  47. } else {
  48. NSWorkspace.shared.open(downloadCrystalFetch)
  49. }
  50. } label: {
  51. Label("Fetch latest Windows installer…", systemImage: "link")
  52. }.buttonStyle(.link)
  53. #endif
  54. Link(destination: URL(string: "https://docs.getutm.app/guides/windows/")!) {
  55. Label("Windows Install Guide", systemImage: "link")
  56. }.buttonStyle(.borderless)
  57. }
  58. } header: {
  59. Text("Image File Type")
  60. }
  61. #endif
  62. Section {
  63. if wizardState.legacyHardware {
  64. Picker("Boot Device", selection: $wizardState.bootDevice) {
  65. Text("CD/DVD Image").tag(VMBootDevice.cd)
  66. Text("Floppy Image").tag(VMBootDevice.floppy)
  67. }.pickerStyle(.inline)
  68. .onAppear {
  69. if !wizardState.legacyHardware && wizardState.bootDevice == .floppy {
  70. wizardState.bootDevice = .cd
  71. }
  72. }
  73. }
  74. FileBrowseField(url: $wizardState.bootImageURL, isFileImporterPresented: $isFileImporterPresented, hasClearButton: false)
  75. if wizardState.isBusy {
  76. Spinner(size: .large)
  77. }
  78. } header: {
  79. if wizardState.bootDevice == .cd {
  80. Text("Boot ISO Image")
  81. } else {
  82. Text("Boot IMG Image")
  83. }
  84. }
  85. if !wizardState.isWindows10OrHigher && !wizardState.legacyHardware {
  86. DetailedSection("", description: "Some older systems do not support UEFI boot, such as Windows 7 and below.") {
  87. Toggle("UEFI Boot", isOn: $wizardState.systemBootUefi)
  88. .onChange(of: wizardState.systemBootUefi) { newValue in
  89. if !newValue {
  90. wizardState.systemBootTpm = false
  91. }
  92. }
  93. Toggle("Secure Boot with TPM 2.0", isOn: $wizardState.systemBootTpm)
  94. .disabled(!wizardState.systemBootUefi)
  95. }
  96. }
  97. // Disabled on iOS 14 due to a SwiftUI layout bug
  98. // Disabled for non-Windows 10 installs due to autounattend version
  99. if #available(iOS 15, *), wizardState.isWindows10OrHigher {
  100. DetailedSection("", description: "Download and mount the guest support package for Windows. This is required for some features including dynamic resolution and clipboard sharing.") {
  101. Toggle("Install drivers and SPICE tools", isOn: $wizardState.isGuestToolsInstallRequested)
  102. }
  103. }
  104. }
  105. .fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.data], onCompletion: processImage)
  106. .onAppear {
  107. wizardState.bootDevice = .cd
  108. #if WITH_QEMU_TCI
  109. wizardState.legacyHardware = true
  110. #endif
  111. if wizardState.legacyHardware {
  112. wizardState.isWindows10OrHigher = false
  113. wizardState.isGuestToolsInstallRequested = false
  114. wizardState.systemBootUefi = false
  115. wizardState.systemBootTpm = false
  116. }
  117. }
  118. }
  119. private func processImage(_ result: Result<URL, Error>) {
  120. wizardState.busyWorkAsync {
  121. let url = try result.get()
  122. await MainActor.run {
  123. wizardState.bootImageURL = url
  124. }
  125. }
  126. }
  127. }
  128. struct VMWizardOSWindowsView_Previews: PreviewProvider {
  129. @StateObject static var wizardState = VMWizardState()
  130. static var previews: some View {
  131. VMWizardOSWindowsView(wizardState: wizardState)
  132. }
  133. }