2
0

VMConfigSharingView.swift 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 VMConfigSharingView: View {
  18. @Binding var config: UTMQemuConfigurationSharing
  19. @State private var isImporterPresented: Bool = false
  20. @EnvironmentObject private var data: UTMData
  21. var body: some View {
  22. VStack {
  23. Form {
  24. DetailedSection("Clipboard Sharing", description: "Requires SPICE guest agent tools to be installed.") {
  25. Toggle(isOn: $config.hasClipboardSharing, label: {
  26. Text("Enable Clipboard Sharing")
  27. })
  28. }
  29. DetailedSection("Shared Directory", description: "WebDAV requires installing SPICE daemon. VirtFS requires installing device drivers.") {
  30. VMConfigConstantPicker("Directory Share Mode", selection: $config.directoryShareMode)
  31. if config.directoryShareMode != .none {
  32. FileBrowseField(url: $config.directoryShareUrl, isFileImporterPresented: $isImporterPresented)
  33. Toggle(isOn: $config.isDirectoryShareReadOnly, label: {
  34. Text("Read Only")
  35. })
  36. }
  37. }.globalFileImporter(isPresented: $isImporterPresented, allowedContentTypes: [.folder]) { result in
  38. data.busyWorkAsync {
  39. let url = try result.get()
  40. await MainActor.run {
  41. config.directoryShareUrl = url
  42. }
  43. }
  44. }
  45. }
  46. }
  47. }
  48. }
  49. struct VMConfigSharingView_Previews: PreviewProvider {
  50. @State static private var config = UTMQemuConfigurationSharing()
  51. static var previews: some View {
  52. VMConfigSharingView(config: $config)
  53. #if os(macOS)
  54. .scrollable()
  55. #endif
  56. }
  57. }