vm(remote): handle SPICE disconnect
This commit is contained in:
parent
f446c1cd8f
commit
b762149671
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@optional
|
||||
- (void)spiceDynamicResolutionSupportDidChange:(BOOL)supported;
|
||||
- (void)spiceDidDisconnect;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"location" : "https://github.com/utmapp/CocoaSpice.git",
|
||||
"state" : {
|
||||
"branch" : "visionos",
|
||||
"revision" : "9d286ba10b8ed953bf21c04ddd64237372163132"
|
||||
"revision" : "9fd682e0f78c884036609d4a19db2cfb3ed50c33"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue