session: force kill vm when multiple VMs are supported
This commit is contained in:
parent
31ebc6fb36
commit
52a1f454be
|
@ -465,10 +465,10 @@ extension VMSessionState {
|
|||
NotificationCenter.default.post(name: .vmSessionEnded, object: nil, userInfo: ["Session": self])
|
||||
}
|
||||
|
||||
func powerDown() {
|
||||
func powerDown(isKill: Bool = false) {
|
||||
Task {
|
||||
try? await vm.deleteSnapshot(name: nil)
|
||||
try await vm.stop(usingMethod: .force)
|
||||
try await vm.stop(usingMethod: isKill ? .kill : .force)
|
||||
self.stop()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,13 +82,17 @@ struct VMToolbarView: View {
|
|||
GeometryReader { geometry in
|
||||
Group {
|
||||
Button {
|
||||
if session.vm.state == .started {
|
||||
if state.isRunning {
|
||||
state.alert = .powerDown
|
||||
} else {
|
||||
state.alert = .terminateApp
|
||||
}
|
||||
} label: {
|
||||
Label(state.isRunning ? "Power Off" : "Quit", systemImage: state.isRunning ? "power" : "xmark")
|
||||
if state.isRunning {
|
||||
Label("Power Off", systemImage: "power")
|
||||
} else {
|
||||
Label("Force Kill", systemImage: "xmark")
|
||||
}
|
||||
}.offset(offset(for: 8))
|
||||
Button {
|
||||
session.pauseResume()
|
||||
|
|
|
@ -108,7 +108,7 @@ struct VMWindowView: View {
|
|||
}, secondaryButton: .cancel(Text("No")))
|
||||
case .terminateApp:
|
||||
return Alert(title: Text("Are you sure you want to exit UTM?"), primaryButton: .destructive(Text("Yes")) {
|
||||
session.stop()
|
||||
session.powerDown(isKill: true)
|
||||
}, secondaryButton: .cancel(Text("No")))
|
||||
case .restart:
|
||||
return Alert(title: Text("Are you sure you want to reset this VM? Any unsaved changes will be lost."), primaryButton: .destructive(Text("Yes")) {
|
||||
|
|
|
@ -25,13 +25,17 @@ struct VMToolbarOrnamentModifier: ViewModifier {
|
|||
content.ornament(visibility: isCollapsed ? .hidden : .visible, attachmentAnchor: .scene(.top)) {
|
||||
HStack {
|
||||
Button {
|
||||
if session.vm.state == .started {
|
||||
if state.isRunning {
|
||||
state.alert = .powerDown
|
||||
} else {
|
||||
state.alert = .terminateApp
|
||||
}
|
||||
} label: {
|
||||
Label(state.isRunning ? "Power Off" : "Quit", systemImage: state.isRunning ? "power" : "xmark")
|
||||
if state.isRunning {
|
||||
Label("Power Off", systemImage: "power")
|
||||
} else {
|
||||
Label("Force Kill", systemImage: "xmark")
|
||||
}
|
||||
}
|
||||
.disabled(state.isBusy)
|
||||
Button {
|
||||
|
|
Loading…
Reference in New Issue