2
0

VMAppleSettingsAddDeviceMenuView.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //
  2. // Copyright © 2022 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 VMAppleSettingsAddDeviceMenuView: View {
  18. @ObservedObject var config: UTMAppleConfiguration
  19. private var isAddDisplayEnabled: Bool {
  20. if #available(macOS 13, *), config.displays.isEmpty && config.system.boot.operatingSystem != .none {
  21. return true
  22. } else if #available(macOS 12, *), config.displays.isEmpty && config.system.boot.operatingSystem == .macOS {
  23. return true
  24. } else {
  25. return false
  26. }
  27. }
  28. var body: some View {
  29. Menu {
  30. Button {
  31. let newDisplay = UTMAppleConfigurationDisplay()
  32. config.displays.append(newDisplay)
  33. } label: {
  34. Label("Display", systemImage: "rectangle.on.rectangle")
  35. }.disabled(!isAddDisplayEnabled)
  36. Button {
  37. let newSerial = UTMAppleConfigurationSerial()
  38. config.serials.append(newSerial)
  39. } label: {
  40. Label("Serial", systemImage: "rectangle.connected.to.line.below")
  41. }
  42. Button {
  43. let newNetwork = UTMAppleConfigurationNetwork()
  44. config.networks.append(newNetwork)
  45. } label: {
  46. Label("Network", systemImage: "network")
  47. }
  48. } label: {
  49. Label("New…", systemImage: "plus")
  50. }.help("Add a new device.")
  51. .menuStyle(.borderlessButton)
  52. }
  53. }
  54. struct VMAppleSettingsAddDeviceMenuView_Previews: PreviewProvider {
  55. @StateObject static private var config = UTMAppleConfiguration()
  56. static var previews: some View {
  57. VMAppleSettingsAddDeviceMenuView(config: config)
  58. }
  59. }