Files
VirtualBuddy/VirtualUI/Source/Session/Configuration/VMSessionConfigurationView.swift
Guilherme Rambo 68c48f8d53 Tunnel settings tweaks (#827)
* Add menu for quickly copying tunnels from other virtual machines, improve default selection for guest vs. host service depending on where the tunnel is being configured

* Count only tunnels that can be added in all tunnels menu option

* Add dedicated toolbar item for tunnel approval

* Fix service tunnels menu button sizing
2026-11-26 11:00:15 -03:00

118 lines
4.3 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.

//
// VMSessionConfigurationView.swift
// VirtualBuddy
//
// Created by Guilherme Rambo on 07/04/22.
//
import SwiftUI
import VirtualCore
struct VMSessionConfigurationView: View {
@EnvironmentObject var controller: VMController
@State private var isShowingVMSettings = false
private var vm: VBVirtualMachine { controller.virtualMachineModel }
private var resolvedRestoreImage: ResolvedRestoreImage? {
let catalog = SoftwareCatalog.current(for: vm.configuration.systemType)
if let remoteURL = vm.metadata.remoteInstallImageURL,
let resolved = catalog.resolvedRestoreImage(matching: remoteURL, guestType: vm.configuration.systemType) {
return resolved
}
if let localURL = vm.metadata.installImageURL,
let resolved = catalog.resolvedRestoreImage(matching: localURL, guestType: vm.configuration.systemType) {
return resolved
}
return nil
}
var body: some View {
SelfSizingGroupedForm(minHeight: 100) {
if let savedSession = controller.savedSession {
SavedSessionDetailsSection(descriptor: savedSession)
} else if let issue = saveEligibilityIssue {
Label {
Text("Save & Close isn’t available. \(issue.explanation)")
.font(.caption)
.foregroundStyle(.secondary)
} icon: {
Image(systemName: "info.circle")
}
}
/// The boot mode of a saved session can't change. Discarding the session is the way to boot differently.
Group {
if showInstallDeviceOption {
Toggle("Boot on install drive", isOn: $controller.options.bootOnInstallDevice)
}
if showRecoveryModeOption {
Toggle("Boot in recovery mode", isOn: $controller.options.bootInRecoveryMode)
.disabled(controller.options.bootInDFUMode)
}
if showDFUOption {
Toggle("Boot in DFU mode", isOn: $controller.options.bootInDFUMode)
.disabled(controller.options.bootInRecoveryMode)
}
}
.disabled(controller.savedSession != nil)
Toggle("Capture system keyboard shortcuts", isOn: $controller.virtualMachineModel.configuration.captureSystemKeys)
Button("Virtual Machine Settings…") {
isShowingVMSettings.toggle()
}
.frame(maxWidth: .infinity, alignment: .trailing)
}
.padding(-12)
.clipShape(shape)
.airMaterialBackground(visualEffect: .hudWindow, glassEffect: .clear, in: shape)
.sheet(isPresented: $isShowingVMSettings) {
VMConfigurationSheet(
configuration: $controller.virtualMachineModel.configuration
)
.environmentObject(makeConfigurationViewModel())
}
}
private func makeConfigurationViewModel() -> VMConfigurationViewModel {
let viewModel = VMConfigurationViewModel(vm, resolvedRestoreImage: resolvedRestoreImage)
viewModel.discardSavedSessionHandler = { [weak controller] in try await controller?.discardSavedSession() }
viewModel.serviceTunnelSources = { [weak controller] in controller?.serviceTunnelSources() ?? [] }
return viewModel
}
private var shape: RoundedRectangle {
RoundedRectangle(cornerRadius: 18)
}
private var showInstallDeviceOption: Bool { vm.configuration.systemType == .linux && vm.metadata.installImageURL != nil }
private var showRecoveryModeOption: Bool { vm.configuration.systemType == .mac }
private var showDFUOption: Bool { VBMacConfiguration.appBuildAllowsDFUMode && vm.configuration.systemType == .mac }
/// Why saving the session isn't available for this virtual machine, shown before the user depends on it.
private var saveEligibilityIssue: SavedSessionEligibility.Issue? {
guard controller.saveEligibility.isApplicable else { return nil }
return controller.saveEligibility.primaryIssue
}
}
#if DEBUG
#Preview("Glass") {
VirtualMachineSessionViewPreview()
}
#Preview("No Glass") {
VirtualMachineSessionViewPreview()
.environment(\.preview_overrideLiquidGlassSupported, false)
}
#endif