Files
VirtualBuddy/VirtualCore/Source/Settings/VirtualBuddyManagedPreferences.swift
Guilherme Rambo 3522f6520c Xcode integration (#818)
* Implement Xcode integration for running and debugging a Mac app in a virtual machine

* Fix xcodeproj/xcworkspace not selectable in open panel

* Improve Xcode project setup UI

* Add dedicated Developer tab in settings and global toggle for developer features

* Improve developer settings UI

* Add managed preference for disabling developer features
2026-11-20 17:37:23 -03:00

138 lines
9.2 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ManagedPreferencesKit
import OSLog
public enum VirtualBuddyManagedPreferences: ManagedPreferencesNamespace {
public static let schema = Schema(domain: "codes.rambo.VirtualBuddy", displayName: "VirtualBuddy") {
Group("Sharing") {
Preference<Bool>.disableSharedFolders
Preference<Bool>.disableGuestApp
Preference<Bool>.disableUSBPassthrough
}
Group("Networking") {
Preference<Bool>.disableBridgedNetworking
}
Group("Audio") {
Preference<Bool>.disableMicrophoneInput
}
Group("Provisioning") {
Preference<Bool>.disableProvisioningRemoteLogin
Preference<Bool>.disableProvisioningAutomaticLogin
}
Group("Developer") {
Preference<Bool>.disableDeveloperFeatures
}
}
static var sharedFoldersDisabled: Bool {
schema.reader().value(for: .disableSharedFolders, default: false)
}
static var guestAppDisabled: Bool { schema.reader().value(for: .disableGuestApp, default: false) }
static var usbPassthroughDisabled: Bool { schema.reader().value(for: .disableUSBPassthrough, default: false) }
static var bridgedNetworkingDisabled: Bool { schema.reader().value(for: .disableBridgedNetworking, default: false) }
static var microphoneInputDisabled: Bool { schema.reader().value(for: .disableMicrophoneInput, default: false) }
static let logger = Logger(subsystem: VirtualCoreConstants.subsystemName, category: "ManagedPreferences")
}
public extension ManagedPreference where Namespace == VirtualBuddyManagedPreferences, Value == Bool {
static let disableDeveloperFeatures = Self("DisableDeveloperFeatures", title: "Disable Developer Features", default: false) {
Summary("Prevents users from enabling developer features or starting Xcode debug runs in virtual machines.")
DefaultBehavior("When absent or false, VirtualBuddy uses the user's Developer Features setting. Invalid values fall back to false.")
Behavior("Locks the Developer Features switch off, hides Xcode debugging setup, and blocks new debug runs from existing schemes.")
Behavior("Users can still delete cached symbols. Removing the restriction restores the user's saved setting.")
Options {
Option(true, "Disable developer features.")
Option(false, "Allow users to choose whether to enable developer features.")
}
}
static let disableProvisioningRemoteLogin = Self("DisableProvisioningRemoteLogin", title: "Disable Provisioning Remote Login", default: false) {
Summary("Prevents VirtualBuddy from enabling remote login (SSH) during macOS guest provisioning.")
DefaultBehavior("The saved provisioning setting is used when this preference is absent or false. Invalid values fall back to false.")
Behavior("Disables the provisioning control and prevents remote login from being enabled during provisioning. The saved selection is preserved.")
Behavior("Does not change remote login in an existing guest or prevent it from being enabled inside the guest.")
Options {
Option(true, "Disable remote login during provisioning.")
Option(false, "Allow remote login during provisioning.")
}
}
static let disableProvisioningAutomaticLogin = Self("DisableProvisioningAutomaticLogin", title: "Disable Provisioning Automatic Login", default: false) {
Summary("Prevents VirtualBuddy from enabling automatic login during macOS guest provisioning.")
DefaultBehavior("The saved provisioning setting is used when this preference is absent or false. Invalid values fall back to false.")
Behavior("Disables the provisioning control and prevents automatic login from being enabled during provisioning. The saved selection is preserved.")
Behavior("Does not change automatic login in an existing guest or prevent it from being enabled inside the guest.")
Options {
Option(true, "Disable automatic login during provisioning.")
Option(false, "Allow automatic login during provisioning.")
}
}
static let disableSharedFolders = Self("DisableSharedFolders", title: "Disable Shared Folders", default: false) {
Summary("Disables host folder sharing for all virtual machines.")
Discussion("Deploy this Boolean in the VirtualBuddy preference domain using an MDM configuration profile. It applies to macOS and Linux guests, including existing virtual machines.")
DefaultBehavior("Shared folders are available when this preference is absent or false. Invalid values fall back to false.")
Behavior("Disables shared folder controls and rejects attempts to edit live folder mappings.")
Behavior("Ignores saved folder mappings when starting or restoring a VM. Mappings remain saved so they can be used after the restriction is removed.")
Behavior("When a policy change is observed, shared folders are disconnected from running VMs. When the restriction is removed, the current session’s folder mappings are shared again.")
Behavior("Rosetta for Linux is unaffected: its separate share exposes Apple's translation runtime, not user-selected host folders.")
Options {
Option(true, "Shared folders are unavailable.")
Option(false, "Shared folders are available.")
}
Example(true, "Disable host folder sharing on managed Macs.")
}
static let disableGuestApp = Self("DisableGuestApp", title: "Disable Guest App Mounting", default: false) {
Summary("Prevents VirtualBuddy from mounting its guest app installer disk.")
DefaultBehavior("The feature follows the VM configuration when this preference is absent or false. Invalid values fall back to false.")
Behavior("Applies when starting a macOS VM. The guest app mounting control is disabled and the installer disk is omitted, including when constructing a VM for snapshot restoration.")
Behavior("Does not uninstall, stop, or disable an app already installed in the guest. Existing guest communication and clipboard sharing are unaffected.")
Behavior("Does not eject an installer disk from an already running VM. Shut down and start the VM to apply this restriction.")
Options {
Option(true, "Apply the restriction.")
Option(false, "Allow the feature.")
}
Example(true, "Restrict this feature on managed Macs.")
}
static let disableUSBPassthrough = Self("DisableUSBPassthrough", title: "Disable USB Passthrough", default: false) {
Summary("Prevents attaching host USB accessories to any VM.")
DefaultBehavior("The feature follows the VM configuration when this preference is absent or false. Invalid values fall back to false.")
Behavior("Disables USB passthrough controls and blocks automatic and manual attachment. Saved device selections are preserved.")
Behavior("When a policy change is observed, attached passthrough devices are detached. Detachment failures are logged and shown in the USB menu.")
Behavior("Emulated USB devices, including virtual keyboards and storage, are unaffected.")
Options {
Option(true, "Apply the restriction.")
Option(false, "Allow the feature.")
}
Example(true, "Restrict this feature on managed Macs.")
}
static let disableBridgedNetworking = Self("DisableBridgedNetworking", title: "Disable Bridged Networking", default: false) {
Summary("Prevents VMs from bridging onto host network interfaces.")
DefaultBehavior("The feature follows the VM configuration when this preference is absent or false. Invalid values fall back to false.")
Behavior("Saved bridged adapters start disconnected. Their configuration is preserved; users can explicitly select NAT or disable networking.")
Behavior("When a policy change is observed, active bridged adapters are disconnected. Interface changes and automatic reconnection cannot bypass the restriction.")
Behavior("NAT networking is unaffected. Restart the VM after removing the restriction to restore saved bridged connections.")
Options {
Option(true, "Apply the restriction.")
Option(false, "Allow the feature.")
}
Example(true, "Restrict this feature on managed Macs.")
}
static let disableMicrophoneInput = Self("DisableMicrophoneInput", title: "Disable Microphone Input", default: false) {
Summary("Prevents VM sound devices from receiving host microphone audio.")
DefaultBehavior("The feature follows the VM configuration when this preference is absent or false. Invalid values fall back to false.")
Behavior("Disables sound input controls and replaces host audio input with silence when constructing the VM. Sound output and saved settings are preserved.")
Behavior("Shut down and start running VMs to apply this restriction. Resuming an existing VM configured with host microphone input is denied while restricted; start it again instead.")
Options {
Option(true, "Apply the restriction.")
Option(false, "Allow the feature.")
}
Example(true, "Restrict this feature on managed Macs.")
}
}