VMWizardSharingView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 VMWizardSharingView: View {
  18. @ObservedObject var wizardState: VMWizardState
  19. @State private var isFileImporterPresented: Bool = false
  20. var body: some View {
  21. VMWizardContent("Shared Directory") {
  22. DetailedSection("Shared Directory Path", description: "Optionally select a directory to make accessible inside the VM. Note that support for shared directories varies by the guest operating system and may require additional guest drivers to be installed. See UTM support pages for more details.") {
  23. FileBrowseField(url: $wizardState.sharingDirectoryURL, isFileImporterPresented: $isFileImporterPresented)
  24. if !wizardState.useAppleVirtualization {
  25. Toggle("Share is read only", isOn: $wizardState.sharingReadOnly)
  26. }
  27. if wizardState.isBusy {
  28. Spinner(size: .large)
  29. }
  30. }
  31. }
  32. .fileImporter(isPresented: $isFileImporterPresented, allowedContentTypes: [.folder], onCompletion: processDirectory)
  33. }
  34. private func processDirectory(_ result: Result<URL, Error>) {
  35. wizardState.busyWorkAsync {
  36. let url = try result.get()
  37. await MainActor.run {
  38. wizardState.sharingDirectoryURL = url
  39. }
  40. }
  41. }
  42. }
  43. struct VMWizardSharingView_Previews: PreviewProvider {
  44. @StateObject static var wizardState = VMWizardState()
  45. static var previews: some View {
  46. VMWizardSharingView(wizardState: wizardState)
  47. }
  48. }