mirror of
https://github.com/utmapp/UTM.git
synced 2026-10-12 02:24:01 +00:00
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
174 lines
7.2 KiB
Swift
174 lines
7.2 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 Virtualization
|
|
import SwiftUI
|
|
|
|
struct VMConfigAppleBootView: View {
|
|
private enum BootloaderSelection: Int, Identifiable {
|
|
var id: Int {
|
|
self.rawValue
|
|
}
|
|
case kernel
|
|
case ramdisk
|
|
case ipsw
|
|
}
|
|
|
|
@Binding var config: UTMAppleConfigurationSystem
|
|
@EnvironmentObject private var data: UTMData
|
|
@State private var operatingSystem: UTMAppleConfigurationBoot.OperatingSystem = .none
|
|
@State private var alertBootloaderSelection: BootloaderSelection?
|
|
@State private var importBootloaderSelection: BootloaderSelection?
|
|
@State private var importFileShown: Bool = false
|
|
|
|
private var currentOperatingSystem: UTMAppleConfigurationBoot.OperatingSystem {
|
|
config.boot.operatingSystem
|
|
}
|
|
|
|
var body: some View {
|
|
Form {
|
|
VMConfigConstantPicker("Operating System", selection: $operatingSystem)
|
|
Picker("Bootloader", selection: $config.boot.hasUefiBoot) {
|
|
Text(operatingSystem.prettyValue).tag(false)
|
|
if #available(macOS 13, *) {
|
|
Text("UEFI").tag(true)
|
|
}
|
|
}
|
|
.onAppear {
|
|
operatingSystem = currentOperatingSystem
|
|
}
|
|
.onChange(of: operatingSystem) { newValue in
|
|
guard newValue != currentOperatingSystem else {
|
|
return
|
|
}
|
|
if newValue == .linux {
|
|
if #available(macOS 13, *) {
|
|
config.boot.hasUefiBoot = true
|
|
config.boot.operatingSystem = .linux
|
|
} else {
|
|
alertBootloaderSelection = .kernel
|
|
}
|
|
} else if newValue == .macOS {
|
|
alertBootloaderSelection = .ipsw
|
|
} else {
|
|
config.boot.operatingSystem = .none
|
|
}
|
|
// don't change display until AFTER file selected
|
|
importBootloaderSelection = nil
|
|
operatingSystem = currentOperatingSystem
|
|
}.onChange(of: config.boot.hasUefiBoot) { newValue in
|
|
if !newValue && operatingSystem == .linux && config.boot.linuxKernelURL == nil {
|
|
alertBootloaderSelection = .kernel
|
|
operatingSystem = .none
|
|
} else if newValue {
|
|
config.genericPlatform = UTMAppleConfigurationGenericPlatform()
|
|
}
|
|
}.alert(item: $alertBootloaderSelection) { selection in
|
|
let okay = Alert.Button.default(Text("OK")) {
|
|
importBootloaderSelection = selection
|
|
importFileShown = true
|
|
}
|
|
switch selection {
|
|
case .kernel:
|
|
return Alert(title: Text("Please select an uncompressed Linux kernel image."), dismissButton: okay)
|
|
case .ipsw:
|
|
return Alert(title: Text("Please select a macOS recovery IPSW."), primaryButton: okay, secondaryButton: .cancel())
|
|
default:
|
|
return Alert(title: Text("Select a file."), dismissButton: okay)
|
|
}
|
|
}.fileImporter(isPresented: $importFileShown,
|
|
allowedContentTypes: [importBootloaderSelection == .ipsw ? .ipsw : .data],
|
|
onCompletion: selectImportedFile)
|
|
|
|
if operatingSystem == .linux && !config.boot.hasUefiBoot {
|
|
Section(header: Text("Linux Settings")) {
|
|
FileBrowseField("Kernel Image", url: $config.boot.linuxKernelURL, isFileImporterPresented: $importFileShown, hasClearButton: false) {
|
|
importBootloaderSelection = .kernel
|
|
}
|
|
FileBrowseField("Ramdisk (optional)", url: $config.boot.linuxInitialRamdiskURL, isFileImporterPresented: $importFileShown) {
|
|
importBootloaderSelection = .ramdisk
|
|
}
|
|
TextField("Boot arguments", text: $config.boot.linuxCommandLine.bound)
|
|
}
|
|
} else if operatingSystem == .macOS {
|
|
#if arch(arm64)
|
|
Section(header: Text("macOS Settings")) {
|
|
FileBrowseField("IPSW Install Image", url: $config.boot.macRecoveryIpswURL, isFileImporterPresented: $importFileShown) {
|
|
importBootloaderSelection = .ipsw
|
|
}
|
|
}
|
|
#endif
|
|
}
|
|
}.onAppear {
|
|
operatingSystem = currentOperatingSystem
|
|
}
|
|
}
|
|
|
|
private func selectImportedFile(result: Result<URL, Error>) {
|
|
// reset operating system to old value
|
|
guard let selection = importBootloaderSelection else {
|
|
return
|
|
}
|
|
data.busyWorkAsync {
|
|
let url = try result.get()
|
|
switch selection {
|
|
case .ipsw:
|
|
#if arch(arm64)
|
|
let scopedAccess = url.startAccessingSecurityScopedResource()
|
|
defer {
|
|
if scopedAccess {
|
|
url.stopAccessingSecurityScopedResource()
|
|
}
|
|
}
|
|
let image = try await VZMacOSRestoreImage.image(from: url)
|
|
guard let model = image.mostFeaturefulSupportedConfiguration?.hardwareModel else {
|
|
throw NSLocalizedString("Your machine does not support running this IPSW.", comment: "VMConfigAppleBootView")
|
|
}
|
|
await MainActor.run {
|
|
config.macPlatform = UTMAppleConfigurationMacPlatform(newHardware: model)
|
|
config.boot.operatingSystem = .macOS
|
|
config.boot.macRecoveryIpswURL = url
|
|
}
|
|
#else
|
|
break
|
|
#endif
|
|
case .kernel:
|
|
await MainActor.run {
|
|
config.genericPlatform = UTMAppleConfigurationGenericPlatform()
|
|
config.boot.operatingSystem = .linux
|
|
config.boot.linuxKernelURL = url
|
|
config.boot.hasUefiBoot = false
|
|
}
|
|
case .ramdisk:
|
|
await MainActor.run {
|
|
config.boot.linuxInitialRamdiskURL = url
|
|
}
|
|
}
|
|
await MainActor.run {
|
|
operatingSystem = currentOperatingSystem
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct VMConfigAppleBootView_Previews: PreviewProvider {
|
|
@State static private var config = UTMAppleConfigurationSystem()
|
|
|
|
static var previews: some View {
|
|
VMConfigAppleBootView(config: $config)
|
|
}
|
|
}
|