Browse Source

project: fix build for iOS

osy 3 years ago
parent
commit
e1e4dea3ac

+ 14 - 4
Managers/UTMSerialPort.swift

@@ -48,13 +48,23 @@ private let kVMDefaultResizeCmd = "stty cols $COLS rows $ROWS\\n"
     }
     
     public func write(data: Data) {
-        try! writeFileHandle.write(contentsOf: data)
+        if #available(iOS 13.4, macOS 10.15, *) {
+            try! writeFileHandle.write(contentsOf: data)
+        } else {
+            writeFileHandle.write(data)
+        }
     }
     
     public func close() {
-        try? readFileHandle.close()
-        try? writeFileHandle.close()
-        try? terminalFileHandle?.close()
+        if #available(iOS 13, macOS 10.15, *) {
+            try? readFileHandle.close()
+            try? writeFileHandle.close()
+            try? terminalFileHandle?.close()
+        } else {
+            readFileHandle.closeFile()
+            writeFileHandle.closeFile()
+            terminalFileHandle?.closeFile()
+        }
     }
     
     public func writeResizeCommand(_ command: String?, columns: Int, rows: Int) {

+ 1 - 0
Platform/Shared/UTMDownloadable.swift

@@ -14,6 +14,7 @@
 // limitations under the License.
 //
 
+@available(iOS 14, macOS 11, *)
 protocol UTMDownloadable {
     var url: URL { get }
     var isDone: Bool { get }

+ 16 - 0
Platform/Shared/VMDetailsView.swift

@@ -62,6 +62,7 @@ struct VMDetailsView: View {
                             .fixedSize(horizontal: false, vertical: true)
                             .padding([.leading, .trailing])
                     }.padding([.leading, .trailing])
+                    #if os(macOS)
                     if #available(macOS 12, *), let appleVM = vm as? UTMAppleVirtualMachine {
                         VMAppleRemovableDrivesView(vm: appleVM, config: appleVM.appleConfig)
                             .padding([.leading, .trailing, .bottom])
@@ -69,6 +70,10 @@ struct VMDetailsView: View {
                         VMRemovableDrivesView(vm: vm as! UTMQemuVirtualMachine)
                             .padding([.leading, .trailing, .bottom])
                     }
+                    #else
+                    VMRemovableDrivesView(vm: vm as! UTMQemuVirtualMachine)
+                        .padding([.leading, .trailing, .bottom])
+                    #endif
                 } else {
                     VStack {
                         Details(vm: vm, sizeLabel: sizeLabel)
@@ -77,17 +82,22 @@ struct VMDetailsView: View {
                                 .font(.body)
                                 .fixedSize(horizontal: false, vertical: true)
                         }
+                        #if os(macOS)
                         if #available(macOS 12, *), let appleVM = vm as? UTMAppleVirtualMachine {
                             VMAppleRemovableDrivesView(vm: appleVM, config: appleVM.appleConfig)
                         } else if let qemuVM = vm as? UTMQemuVirtualMachine {
                             VMRemovableDrivesView(vm: qemuVM)
                         }
+                        #else
+                        VMRemovableDrivesView(vm: vm as! UTMQemuVirtualMachine)
+                        #endif
                     }.padding([.leading, .trailing, .bottom])
                 }
             }.labelStyle(DetailsLabelStyle())
             .modifier(VMOptionalNavigationTitleModifier(vm: vm))
             .modifier(VMToolbarModifier(vm: vm, bottom: !regularScreenSizeClass))
             .sheet(isPresented: $data.showSettingsModal) {
+                #if os(macOS)
                 if #available(macOS 12, *), let appleVM = vm as? UTMAppleVirtualMachine {
                     VMSettingsView(vm: appleVM, config: appleVM.appleConfig)
                         .environmentObject(data)
@@ -95,6 +105,10 @@ struct VMDetailsView: View {
                     VMSettingsView(vm: qemuVM, config: qemuVM.qemuConfig)
                         .environmentObject(data)
                 }
+                #else
+                VMSettingsView(vm: vm as! UTMQemuVirtualMachine, config: vm.config as! UTMQemuConfiguration)
+                    .environmentObject(data)
+                #endif
             }
         }
     }
@@ -186,6 +200,7 @@ struct Details: View {
                 Text(sizeLabel)
                     .foregroundColor(.secondary)
             }
+            #if os(macOS)
             if #available(macOS 12, *), let appleVM = vm as? UTMAppleVirtualMachine {
                 HStack {
                     plainLabel("Serial", systemImage: "phone.connection")
@@ -195,6 +210,7 @@ struct Details: View {
                         .textSelection(.enabled)
                 }
             }
+            #endif
         }.lineLimit(1)
         .truncationMode(.tail)
     }

+ 1 - 1
Platform/Shared/VMWizardOSMacView.swift

@@ -33,7 +33,6 @@ struct VMWizardOSMacView: View {
                 Text(selected.lastPathComponent)
                     .font(.caption)
             }
-            #endif
             HStack {
                 Button {
                     isFileImporterPresented.toggle()
@@ -48,6 +47,7 @@ struct VMWizardOSMacView: View {
                 }
             }.disabled(wizardState.isBusy)
             .buttonStyle(BrowseButtonStyle())
+            #endif
             if wizardState.isBusy {
                 BigWhiteSpinner()
             }

+ 2 - 0
Platform/Shared/VMWizardState.swift

@@ -16,7 +16,9 @@
 
 import Foundation
 import SwiftUI
+#if canImport(Virtualization)
 import Virtualization
+#endif
 
 enum VMWizardPage: Int, Identifiable {
     var id: Int {

+ 1 - 1
Platform/iOS/Display/VMRemovableDrivesViewController.swift

@@ -17,7 +17,7 @@
 @objc class VMRemovableDrivesViewController: UIViewController {
     @IBOutlet weak var doneButton: UIButton!
     @IBOutlet weak var tableView: UITableView!
-    @objc weak var vm: UTMVirtualMachine?
+    @objc weak var vm: UTMQemuVirtualMachine?
     fileprivate var drives: [UTMDrive]?
     fileprivate var selectedDrive: UTMDrive?
     

+ 2 - 2
Platform/iOS/UTMDataExtension.swift

@@ -71,8 +71,8 @@ extension UTMData {
     }
     
     func trySendTextSpice(_ text: String) {
-        if let vc = vmVC as? VMDisplayMetalViewController, let input = vc.vmInput {
-            vc.keyboardView?.insertText(text)
+        if let vc = vmVC as? VMDisplayMetalViewController {
+            vc.keyboardView.insertText(text)
         }
     }
 }

+ 1 - 0
Platform/iOS/VMWizardView.swift

@@ -36,6 +36,7 @@ fileprivate struct WizardWrapper: View {
     @ObservedObject var wizardState: VMWizardState
     @State private var nextPage: VMWizardPage?
     @Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
+    @EnvironmentObject private var data: UTMData
     
     var body: some View {
         VStack {