Files
UTM/Platform/iOS/VMWizardView.swift
osy f3645d5018 project: remove code for versions below the new minimum
Now that the deployment targets are iOS 15 and macOS 12, every guard,
fallback and workaround for an older release is dead code that only
obscures what the supported path is. Remove them:

- Drop the `@available` attributes for iOS 15, macOS 11 and macOS 12, and
  unwrap the matching `#available`/`#unavailable` guards in Swift and the
  `@available`/`API_AVAILABLE`/`NS_AVAILABLE_IOS` ones in Objective-C.
- Delete the legacy-only views and helpers left unreachable by that:
  NumberTextFieldOld, VMConfigNetworkPortForwardLegacyView,
  VMContextMenuModifier.bodyBigSur, the nonbrokenSheet, uniqued,
  customBadge, borderedList and legacySettingsToolbar shims, the
  .unsupported BootloaderSelection case, and the iOS 14 sacrificial
  version Section in the QEMU settings list.
- jb_has_cs_execseg_allow_unsigned() has returned false for every host
  since iOS 14.4, so drop it along with the is_device_A12_or_newer()
  helper that only it used. The entitlement parser no longer needs to
  copy the blob either, since that copy existed only so the psychic paper
  needle could be blanked in place.
- VMDisplayTerminalViewController tracked the keyboard frame by hand for
  iOS 14. `useAutoLayout` is a constant that cannot be overridden, so
  nothing ever registered the notification observers and only the
  keyboardLayoutGuide path is reachable.
- VMConfigQEMUView's additionalArguments is now referenced on iOS only,
  which leaves its macOS branch, and the macOS 11 ForEach crash
  workaround inside it, unreachable.
- Raise the Cydia package floor and the postinst/prerm helpers to match
  the new minimum.

Two of the removed guards dropped an error path rather than just a
branch. The shared directory `featureNotSupported` throw covered
VZVirtioFileSystemDeviceConfiguration and friends being macOS 12+, which
no longer applies to any supported host. The macOS guest
`platformUnsupported` throw when decoding a boot config on Intel only
fired on macOS 11; the Apple Silicon requirement it really guards is
enforced unconditionally in
UTMAppleConfigurationSystem.fillVZConfiguration, which both the start and
the save path go through.

Assisted-by: Claude:claude-opus-5
2026-09-16 04:48:37 +02:00

201 lines
8.5 KiB
Swift

//
// Copyright © 2021 osy. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
struct VMWizardView: View {
@StateObject var wizardState = VMWizardState()
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
var body: some View {
if #available(iOS 16, visionOS 1.0, *) {
WizardNavigationView(wizardState: wizardState) {
presentationMode.wrappedValue.dismiss()
}
} else {
NavigationView {
WizardWrapper(page: .start, wizardState: wizardState) {
presentationMode.wrappedValue.dismiss()
}
}
.navigationViewStyle(.stack)
.alert(item: $wizardState.alertMessage) { msg in
Alert(title: Text(msg.message))
}
}
}
}
fileprivate struct WizardToolbar: ViewModifier {
@ObservedObject var wizardState: VMWizardState
let onDismiss: () -> Void
@EnvironmentObject private var data: UTMData
func body(content: Content) -> some View {
content.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
if wizardState.currentPage == .start {
Button("Cancel") {
onDismiss()
}
}
}
ToolbarItem(placement: .navigationBarTrailing) {
if wizardState.hasNextButton {
Button("Continue") {
wizardState.next()
}
} else if wizardState.currentPage == .summary {
Button("Save") {
onDismiss()
data.busyWorkAsync {
let config = try await wizardState.generateConfig()
if let qemuConfig = config as? UTMQemuConfiguration {
let vm = try await data.create(config: qemuConfig)
await MainActor.run {
if wizardState.isGuestToolsInstallRequested {
NotificationCenter.default.post(name: NSNotification.InstallGuestTools, object: vm.wrapped!)
}
}
} else {
fatalError("Invalid configuration type.")
}
if await wizardState.isOpenSettingsAfterCreation {
await data.showSettingsForCurrentVM()
}
}
}
}
}
}
}
}
@available(iOS, deprecated: 17, message: "Use WizardViewWrapper")
@available(visionOS, deprecated: 1, message: "Use WizardViewWrapper")
fileprivate struct WizardWrapper: View {
let page: VMWizardPage
@ObservedObject var wizardState: VMWizardState
@State private var nextPage: VMWizardPage?
let onDismiss: () -> Void
@EnvironmentObject private var data: UTMData
var body: some View {
VStack {
WizardViewWrapper(page: page, wizardState: wizardState)
NavigationLink(destination: WizardWrapper(page: .start, wizardState: wizardState, onDismiss: onDismiss), tag: .start, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .operatingSystem, wizardState: wizardState, onDismiss: onDismiss), tag: .operatingSystem, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .linuxBoot, wizardState: wizardState, onDismiss: onDismiss), tag: .linuxBoot, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .windowsBoot, wizardState: wizardState, onDismiss: onDismiss), tag: .windowsBoot, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .classicMacOSBoot, wizardState: wizardState, onDismiss: onDismiss), tag: .classicMacOSBoot, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .otherBoot, wizardState: wizardState, onDismiss: onDismiss), tag: .otherBoot, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .hardware, wizardState: wizardState, onDismiss: onDismiss), tag: .hardware, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .drives, wizardState: wizardState, onDismiss: onDismiss), tag: .drives, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .sharing, wizardState: wizardState, onDismiss: onDismiss), tag: .sharing, selection: $nextPage) {}
NavigationLink(destination: WizardWrapper(page: .summary, wizardState: wizardState, onDismiss: onDismiss), tag: .summary, selection: $nextPage) {}
}
.listStyle(.insetGrouped) // needed for iOS 14
.textFieldStyle(.roundedBorder)
.modifier(WizardToolbar(wizardState: wizardState, onDismiss: onDismiss))
.onChange(of: nextPage) { newPage in
if newPage == nil {
wizardState.currentPage = page
wizardState.nextPageBinding = $nextPage
}
}
.onAppear {
wizardState.currentPage = page
wizardState.nextPageBinding = $nextPage
}
.disabled(wizardState.isBusy)
}
}
@available(iOS 16, visionOS 1.0, *)
fileprivate struct WizardNavigationView: View {
@StateObject var wizardState = VMWizardState()
let onDismiss: () -> Void
@Environment(\.presentationMode) private var presentationMode: Binding<PresentationMode>
@State private var navigationPath: NavigationPath = .init()
@State private var previousPage: VMWizardPage?
@State private var isAlertShown: Bool = false
var body: some View {
NavigationStack(path: $wizardState.pageHistory) {
WizardViewWrapper(page: .start, wizardState: wizardState)
.modifier(WizardToolbar(wizardState: wizardState, onDismiss: onDismiss))
.navigationDestination(for: VMWizardPage.self) { page in
WizardViewWrapper(page: page, wizardState: wizardState)
.modifier(WizardToolbar(wizardState: wizardState, onDismiss: onDismiss))
}
.textFieldStyle(.roundedBorder)
.disabled(wizardState.isBusy)
}
.alert("Error", isPresented: $isAlertShown) {
Button("OK", role: .cancel) {
wizardState.alertMessage = nil
}
} message: {
Text(wizardState.alertMessage?.message ?? "")
}
.onChange(of: wizardState.alertMessage?.message) { newValue in
isAlertShown = newValue != nil
}
}
}
fileprivate struct WizardViewWrapper: View {
let page: VMWizardPage
@ObservedObject var wizardState: VMWizardState
var body: some View {
switch page {
case .start:
#if WITH_QEMU_TCI
VMWizardStartViewTCI(wizardState: wizardState)
#else
VMWizardStartView(wizardState: wizardState)
#endif
case .operatingSystem:
VMWizardOSView(wizardState: wizardState)
case .macOSBoot:
EmptyView()
case .linuxBoot:
VMWizardOSLinuxView(wizardState: wizardState)
case .windowsBoot:
VMWizardOSWindowsView(wizardState: wizardState)
case .otherBoot:
VMWizardOSOtherView(wizardState: wizardState)
case .classicMacOSBoot:
VMWizardOSClassicMacView(wizardState: wizardState)
case .hardware:
VMWizardHardwareView(wizardState: wizardState)
case .drives:
VMWizardDrivesView(wizardState: wizardState)
case .sharing:
VMWizardSharingView(wizardState: wizardState)
case .summary:
VMWizardSummaryView(wizardState: wizardState)
}
}
}
struct VMWizardView_Previews: PreviewProvider {
static var previews: some View {
VMWizardView()
}
}