Files
VirtualBuddy/VirtualUI/Source/VM Configuration/Sections/SoundConfigurationView.swift
Guilherme Rambo a20d94dbc5 Implement support for managed preferences (#765)
* Implement support for managed preferences; allow disabling shared folders with managed preferences

* Implement managed preferences for USB passthrough, bridged networking, guest app, and microphone input

* Implement unified UI component for informing user about managed preference restrictions
2026-09-14 17:15:41 -03:00

58 lines
1.7 KiB
Swift

//
// SoundConfigurationView.swift
// VirtualUI
//
// Created by Guilherme Rambo on 18/07/22.
//
import SwiftUI
import VirtualCore
import ManagedPreferencesUI
struct SoundConfigurationView: View {
@Binding var hardware: VBMacDevice
@ManagedValue(for: .disableMicrophoneInput, schema: VirtualBuddyManagedPreferences.schema, default: false)
private var microphoneInputDisabled: Bool
var body: some View {
VStack(alignment: .leading, spacing: 16) {
Toggle("Enable Sound", isOn: soundEnabled)
if hardware.soundDevices.isEmpty || microphoneInputDisabled {
Toggle("Enable Sound Input", isOn: .constant(false))
.disabled(true)
} else {
Toggle("Enable Sound Input", isOn: $hardware.soundDevices[0].enableInput)
}
if microphoneInputDisabled {
ManagedRestrictionBannerView(title: "Microphone input is disabled by your organization.")
Text("Restart the VM to apply.")
.font(.caption)
.foregroundStyle(.secondary)
}
}
}
private var soundEnabled: Binding<Bool> {
.init(get: {
!hardware.soundDevices.isEmpty
}, set: { newValue in
if newValue, hardware.soundDevices.isEmpty {
hardware.soundDevices = [.default]
} else {
hardware.soundDevices.removeAll()
}
})
}
}
#if DEBUG
struct SoundConfigurationView_Previews: PreviewProvider {
static var previews: some View {
_ConfigurationSectionPreview { SoundConfigurationView(hardware: $0.hardware) }
}
}
#endif