From 8779e3624ad43c5ad7090939489840de54de62c7 Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Mon, 19 Aug 2024 18:32:28 -0500 Subject: [PATCH] remote: fix list not showing when a single VM is unavailable Fixes #6380 --- Platform/Shared/UTMUnavailableVMView.swift | 4 ++++ Platform/VMData.swift | 2 +- Remote/UTMRemoteServer.swift | 15 +++++++++------ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Platform/Shared/UTMUnavailableVMView.swift b/Platform/Shared/UTMUnavailableVMView.swift index 8e687345..6252417e 100644 --- a/Platform/Shared/UTMUnavailableVMView.swift +++ b/Platform/Shared/UTMUnavailableVMView.swift @@ -73,6 +73,8 @@ fileprivate struct WrappedVMDetailsView: View { } #if os(macOS) .frame(width: 230) + #else + .padding() #endif } } @@ -92,6 +94,8 @@ fileprivate struct UnsupportedVMDetailsView: View { } #if os(macOS) .frame(width: 230) + #else + .padding() #endif } } diff --git a/Platform/VMData.swift b/Platform/VMData.swift index f96826e2..fb70720b 100644 --- a/Platform/VMData.swift +++ b/Platform/VMData.swift @@ -521,7 +521,7 @@ extension VMRemoteDataError: LocalizedError { case .notImplemented: return NSLocalizedString("This function is not implemented.", comment: "VMData") case .backendNotSupported: - return NSLocalizedString("This VM is configured for a backend that does not support remote clients.", comment: "VMData") + return NSLocalizedString("This VM is not available or is configured for a backend that does not support remote clients.", comment: "VMData") } } } diff --git a/Remote/UTMRemoteServer.swift b/Remote/UTMRemoteServer.swift index 7a50dede..b9fea5f7 100644 --- a/Remote/UTMRemoteServer.swift +++ b/Remote/UTMRemoteServer.swift @@ -683,13 +683,16 @@ extension UTMRemoteServer { } @MainActor - private func findVM(withId id: UUID) throws -> VMData { + private func findVM(withId id: UUID, allowNotLoaded: Bool = false) throws -> VMData { let vm = data.virtualMachines.first(where: { $0.id == id }) - if let vm = vm, let _ = vm.wrapped { - return vm - } else { - throw UTMRemoteServer.ServerError.notFound(id) + if let vm = vm { + if let _ = vm.wrapped { + return vm + } else if allowNotLoaded { + return vm + } } + throw UTMRemoteServer.ServerError.notFound(id) } @MainActor @@ -735,7 +738,7 @@ extension UTMRemoteServer { private func _getVirtualMachineInformation(parameters: M.GetVirtualMachineInformation.Request) async throws -> M.GetVirtualMachineInformation.Reply { let informations = try await Task { @MainActor in try parameters.ids.map { id in - let vm = try findVM(withId: id) + let vm = try findVM(withId: id, allowNotLoaded: true) let mountedDrives = vm.registryEntry?.externalDrives.mapValues({ $0.path }) ?? [:] let isTakeoverAllowed = data.vmWindows[vm] is VMRemoteSessionState && (vm.state == .started || vm.state == .paused) return M.VirtualMachineInformation(id: vm.id,