Преглед на файлове

Fix for crash while connecting in UTM Remote for iOS 14 (#7034)

* Modified the behaviour of function for await connect to the server

* Added missing environment object for ServerConnectView

* Update README.md for explanation of the problem and the fix

* Update README.md
tearsinthegame преди 4 месеца
родител
ревизия
24b3c5ca5c
променени са 1 файла, в които са добавени 47 реда и са изтрити 17 реда
  1. 47 17
      Platform/iOS/UTMRemoteConnectView.swift

+ 47 - 17
Platform/iOS/UTMRemoteConnectView.swift

@@ -107,7 +107,12 @@ struct UTMRemoteConnectView: View {
             })
         }
         .sheet(item: $selectedServer) { server in
-            ServerConnectView(remoteClientState: remoteClientState, server: server, isAutoConnect: $isAutoConnect)
+            if #available(iOS 15, *) {
+                ServerConnectView(remoteClientState: remoteClientState, server: server, isAutoConnect: $isAutoConnect)
+            } else {
+                ServerConnectView(remoteClientState: remoteClientState, server: server, isAutoConnect: $isAutoConnect)
+                    .environmentObject(data)
+            }
         }
         .onAppear {
             Task {
@@ -262,24 +267,49 @@ private struct ServerConnectView: View {
                 connectionTask?.cancel()
                 remoteClientState.showErrorAlert(NSLocalizedString("Timed out trying to connect.", comment: "UTMRemoteConnectView"))
             }
-            do {
-                try await remoteClient.connect(server)
-            } catch {
-                if case UTMRemoteClient.ConnectionError.passwordRequired = error {
-                    withAnimation {
-                        isPasswordRequired = true
-                        isTrustButton = false
+            if #available(iOS 15, *) {
+                do {
+                    try await remoteClient.connect(server)
+                } catch {
+                    if case UTMRemoteClient.ConnectionError.passwordRequired = error {
+                        withAnimation {
+                            isPasswordRequired = true
+                            isTrustButton = false
+                        }
+                    } else if case UTMRemoteClient.ConnectionError.fingerprintUntrusted(let fingerprint) = error, server.fingerprint.isEmpty {
+                        withAnimation {
+                            server.fingerprint = fingerprint
+                            isTrustButton = true
+                        }
+                        remoteClientState.showErrorAlert(error.localizedDescription)
+                    } else if error is CancellationError {
+                        // ignore it
+                    } else {
+                        remoteClientState.showErrorAlert(error.localizedDescription)
                     }
-                } else if case UTMRemoteClient.ConnectionError.fingerprintUntrusted(let fingerprint) = error, server.fingerprint.isEmpty {
-                    withAnimation {
-                        server.fingerprint = fingerprint
-                        isTrustButton = true
+                }
+            } else {
+                Task(priority: .userInteractive) {
+                    do {
+                        try await remoteClient.connect(server)
+                    } catch {
+                        if case UTMRemoteClient.ConnectionError.passwordRequired = error {
+                            withAnimation {
+                                isPasswordRequired = true
+                                isTrustButton = false
+                            }
+                        } else if case UTMRemoteClient.ConnectionError.fingerprintUntrusted(let fingerprint) = error, server.fingerprint.isEmpty {
+                            withAnimation {
+                                server.fingerprint = fingerprint
+                                isTrustButton = true
+                            }
+                            remoteClientState.showErrorAlert(error.localizedDescription)
+                        } else if error is CancellationError {
+                            // ignore it
+                        } else {
+                            remoteClientState.showErrorAlert(error.localizedDescription)
+                        }
                     }
-                    remoteClientState.showErrorAlert(error.localizedDescription)
-                } else if error is CancellationError {
-                    // ignore it
-                } else {
-                    remoteClientState.showErrorAlert(error.localizedDescription)
                 }
             }
             timeoutTask.cancel()