From 3cabe41027bddfd90825c719af9d9bb0a80adc2f Mon Sep 17 00:00:00 2001 From: osy <50960678+osy@users.noreply.github.com> Date: Mon, 7 Apr 2025 08:58:52 -0700 Subject: [PATCH] remote(client): improve flow when local network access is denied --- Platform/iOS/UTMRemoteConnectView.swift | 12 +++++++++++- Remote/UTMRemoteClient.swift | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Platform/iOS/UTMRemoteConnectView.swift b/Platform/iOS/UTMRemoteConnectView.swift index 04390c88..ffeafc39 100644 --- a/Platform/iOS/UTMRemoteConnectView.swift +++ b/Platform/iOS/UTMRemoteConnectView.swift @@ -21,6 +21,7 @@ private let kTimeoutSeconds: UInt64 = 15 struct UTMRemoteConnectView: View { @ObservedObject var remoteClientState: UTMRemoteClient.State @Environment(\.openURL) private var openURL + @Environment(\.scenePhase) private var scenePhase @EnvironmentObject private var data: UTMRemoteData @State private var selectedServer: UTMRemoteClient.State.SavedServer? @State private var isAutoConnect: Bool = false @@ -98,7 +99,9 @@ struct UTMRemoteConnectView: View { } }.listStyle(.insetGrouped) }.alert(item: $remoteClientState.alertMessage) { item in - Alert(title: Text(item.message), dismissButton: .default(Text("Retry")) { + Alert(title: Text(item.message), primaryButton: .default(Text("Open Settings")) { + UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!) + }, secondaryButton: .cancel(Text("Retry")) { if !remoteClientState.isScanning { Task { await remoteClient.startScanning() @@ -124,6 +127,13 @@ struct UTMRemoteConnectView: View { await remoteClient.stopScanning() } } + .onChange(of: scenePhase) { newValue in + if newValue == .active && !remoteClientState.isScanning { + Task { + await remoteClient.startScanning() + } + } + } } @ViewBuilder diff --git a/Remote/UTMRemoteClient.swift b/Remote/UTMRemoteClient.swift index be645d7e..0eeae7fa 100644 --- a/Remote/UTMRemoteClient.swift +++ b/Remote/UTMRemoteClient.swift @@ -599,7 +599,7 @@ extension Connection.ConnectionError: @retroactive LocalizedError { public var errorDescription: String? { switch self { case .localNetworkDenied: - return NSLocalizedString("Please allow this app to access your local network when prompted.", comment: "UTMRemoteClient") + return NSLocalizedString("Please allow this app to access your local network when prompted or in Settings.", comment: "UTMRemoteClient") } } }