瀏覽代碼

vm(remote): handle SPICE disconnect

osy 1 年之前
父節點
當前提交
b762149671

+ 9 - 1
Platform/iOS/VMSessionState.swift

@@ -46,7 +46,9 @@ import SwiftUI
     @Published var vmState: UTMVirtualMachineState = .stopped
     
     @Published var nonfatalError: String?
-    
+
+    @Published var fatalError: String?
+
     @Published var primaryInput: CSInput?
     
     #if WITH_USB
@@ -297,6 +299,12 @@ extension VMSessionState: UTMSpiceIODelegate {
             isDynamicResolutionSupported = supported
         }
     }
+
+    nonisolated func spiceDidDisconnect() {
+        Task { @MainActor in
+            fatalError = NSLocalizedString("Connection to the server was lost.", comment: "VMSessionState")
+        }
+    }
 }
 
 #if WITH_USB

+ 5 - 0
Platform/iOS/VMWindowView.swift

@@ -163,6 +163,11 @@ struct VMWindowView: View {
                 state.alert = .nonfatalError(message)
             }
         }
+        .onChange(of: session.fatalError) { newValue in
+            if session.activeWindow == state.id, let message = newValue {
+                state.alert = .fatalError(message)
+            }
+        }
         .onChange(of: session.vmState) { [oldValue = session.vmState] newValue in
             vmStateUpdated(from: oldValue, to: newValue)
         }

+ 7 - 3
Services/UTMSpiceIO.m

@@ -204,6 +204,7 @@ NSString *const kUTMErrorDomain = @"com.utmapp.utm";
 - (void)spiceDisconnected:(CSConnection *)connection {
     NSAssert(connection == self.spiceConnection, @"Unknown connection");
     self.isConnected = NO;
+    [self.delegate spiceDidDisconnect];
 }
 
 - (void)spiceError:(CSConnection *)connection code:(CSConnectionError)code message:(nullable NSString *)message {
@@ -233,6 +234,9 @@ NSString *const kUTMErrorDomain = @"com.utmapp.utm";
 - (void)spiceDisplayDestroyed:(CSConnection *)connection display:(CSDisplay *)display {
     NSAssert(connection == self.spiceConnection, @"Unknown connection");
     [self.mutableDisplays removeObject:display];
+    if (self.primaryDisplay == display) {
+        self.primaryDisplay = nil;
+    }
     [self.delegate spiceDidDestroyDisplay:display];
 }
 
@@ -271,11 +275,11 @@ NSString *const kUTMErrorDomain = @"com.utmapp.utm";
     }
     if ([port.name isEqualToString:@"org.qemu.guest_agent.0"]) {
     }
-    if ([port.name isEqualToString:@"com.utmapp.terminal.0"]) {
-        self.primarySerial = port;
-    }
     if ([port.name hasPrefix:@"com.utmapp.terminal."]) {
         [self.mutableSerials removeObject:port];
+        if (self.primarySerial == port) {
+            self.primarySerial = nil;
+        }
         [self.delegate spiceDidDestroySerial:port];
     }
 }

+ 1 - 0
Services/UTMSpiceIODelegate.h

@@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
 
 @optional
 - (void)spiceDynamicResolutionSupportDidChange:(BOOL)supported;
+- (void)spiceDidDisconnect;
 
 @end
 

+ 1 - 1
UTM.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -15,7 +15,7 @@
       "location" : "https://github.com/utmapp/CocoaSpice.git",
       "state" : {
         "branch" : "visionos",
-        "revision" : "9d286ba10b8ed953bf21c04ddd64237372163132"
+        "revision" : "9fd682e0f78c884036609d4a19db2cfb3ed50c33"
       }
     },
     {