VMConfigInputView.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // Copyright © 2020 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 VMConfigInputView: View {
  18. @Binding var config: UTMQemuConfigurationInput
  19. let hasUsbSupport: Bool
  20. var body: some View {
  21. VStack {
  22. Form {
  23. DetailedSection("USB", description: "If enabled, the default input devices will be emulated on the USB bus.") {
  24. VMConfigConstantPicker("USB Support", selection: $config.usbBusSupport)
  25. .disabled(!hasUsbSupport)
  26. }
  27. #if WITH_USB
  28. if config.usbBusSupport != .disabled {
  29. Section(header: Text("USB Sharing")) {
  30. if !jb_has_usb_entitlement() {
  31. Text("USB sharing not supported in this build of UTM.")
  32. }
  33. Toggle(isOn: $config.hasUsbSharing) {
  34. Text("Share USB devices from host")
  35. }
  36. HStack {
  37. Stepper(value: $config.maximumUsbShare, in: 0...64) {
  38. Text("Maximum Shared USB Devices")
  39. }
  40. NumberTextField("", number: $config.maximumUsbShare, onEditingChanged: validateMaxUsb)
  41. .frame(width: 50)
  42. .multilineTextAlignment(.trailing)
  43. }
  44. }.disabled(!jb_has_usb_entitlement())
  45. }
  46. #endif
  47. GestureSettingsSection()
  48. }
  49. }
  50. }
  51. private func validateMaxUsb(editing: Bool) {
  52. guard !editing else {
  53. return
  54. }
  55. if config.maximumUsbShare < 0 {
  56. config.maximumUsbShare = 0
  57. } else if config.maximumUsbShare > 64 {
  58. config.maximumUsbShare = 64
  59. }
  60. }
  61. }
  62. fileprivate enum UsbSupport: Int, Identifiable {
  63. case off
  64. case usb2
  65. case usb3
  66. var id: Int {
  67. self.rawValue
  68. }
  69. }
  70. #if os(macOS) || os(visionOS)
  71. @available(macOS 11, *)
  72. struct GestureSettingsSection: View {
  73. var body: some View {
  74. EmptyView()
  75. }
  76. }
  77. #else
  78. struct GestureSettingsSection: View {
  79. var body: some View {
  80. Section(header: Text("Additional Settings")) {
  81. Button(action: {
  82. UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)
  83. }, label: {
  84. Text("Gesture and Cursor Settings")
  85. })
  86. }
  87. }
  88. }
  89. #endif
  90. struct VMConfigInputView_Previews: PreviewProvider {
  91. @State static private var config = UTMQemuConfigurationInput()
  92. static var previews: some View {
  93. VMConfigInputView(config: $config, hasUsbSupport: true)
  94. #if os(macOS)
  95. .scrollable()
  96. #endif
  97. }
  98. }