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
114 lines
5.1 KiB
Swift
114 lines
5.1 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 SavePanel: NSViewRepresentable {
|
|
@EnvironmentObject private var data: UTMData
|
|
@Binding var isPresented: Bool
|
|
var shareItem: VMShareItemModifier.ShareItem?
|
|
|
|
func makeNSView(context: Context) -> some NSView {
|
|
return NSView()
|
|
}
|
|
|
|
func updateNSView(_ nsView: NSViewType, context: Context) {
|
|
if isPresented {
|
|
guard let shareItem = shareItem else {
|
|
return
|
|
}
|
|
|
|
guard let window = nsView.window else {
|
|
return
|
|
}
|
|
|
|
// Initializing the SavePanel and setting its properties
|
|
let savePanel = NSSavePanel()
|
|
if let downloadsUrl = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first {
|
|
savePanel.directoryURL = downloadsUrl
|
|
}
|
|
|
|
switch shareItem {
|
|
case .debugLog:
|
|
savePanel.title = NSLocalizedString("Select where to save debug log:", comment: "SavePanel")
|
|
savePanel.nameFieldStringValue = "debug"
|
|
savePanel.allowedContentTypes = [.appleLog]
|
|
case .utmCopy(let vm), .utmMove(let vm):
|
|
savePanel.title = NSLocalizedString("Select where to save UTM Virtual Machine:", comment: "SavePanel")
|
|
savePanel.nameFieldStringValue = vm.pathUrl.lastPathComponent
|
|
savePanel.allowedContentTypes = [.UTM]
|
|
case .qemuCommand:
|
|
savePanel.title = NSLocalizedString("Select where to export QEMU command:", comment: "SavePanel")
|
|
savePanel.nameFieldStringValue = "command"
|
|
savePanel.allowedContentTypes = [.plainText]
|
|
}
|
|
|
|
// Calling savePanel.begin with the appropriate completion handlers
|
|
// SwiftUI BUG: if we don't wait, there is a crash due to an access issue
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + .milliseconds(100)) {
|
|
switch shareItem {
|
|
case .debugLog(let sourceUrl):
|
|
savePanel.beginSheetModal(for: window) { result in
|
|
if result == .OK {
|
|
if let destUrl = savePanel.url {
|
|
data.busyWorkAsync {
|
|
let fileManager = FileManager.default
|
|
|
|
// All this mess is because FileManager.replaceItemAt deletes the source item
|
|
let tempUrl = fileManager.temporaryDirectory.appendingPathComponent(sourceUrl.lastPathComponent)
|
|
if fileManager.fileExists(atPath: tempUrl.path) {
|
|
try fileManager.removeItem(at: tempUrl)
|
|
}
|
|
try fileManager.copyItem(at: sourceUrl, to: tempUrl)
|
|
|
|
_ = try fileManager.replaceItemAt(destUrl, withItemAt: tempUrl)
|
|
}
|
|
}
|
|
}
|
|
isPresented = false
|
|
}
|
|
case .utmCopy(let vm), .utmMove(let vm):
|
|
savePanel.beginSheetModal(for: window) { result in
|
|
if result == .OK {
|
|
if let destUrl = savePanel.url {
|
|
data.busyWorkAsync {
|
|
if case .utmMove(_) = shareItem {
|
|
try await data.move(vm: vm, to: destUrl)
|
|
} else {
|
|
try await data.export(vm: vm, to: destUrl)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
isPresented = false
|
|
}
|
|
case .qemuCommand(let command):
|
|
savePanel.beginSheetModal(for: window) { result in
|
|
if result == .OK {
|
|
if let destUrl = savePanel.url {
|
|
data.busyWork {
|
|
try command.write(to: destUrl, atomically: true, encoding: .utf8)
|
|
}
|
|
}
|
|
}
|
|
isPresented = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|