Kaynağa Gözat

remote(client): improve flow when local network access is denied

osy 4 ay önce
ebeveyn
işleme
3cabe41027

+ 11 - 1
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

+ 1 - 1
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")
         }
     }
 }