Skip to content

Commit 8dcce62

Browse files
committed
fixed issue #150 terminating GUI app when stopped
1 parent 9390f28 commit 8dcce62

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

example/gui-linux/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func run(ctx context.Context) error {
9494
}
9595

9696
runtime.LockOSThread()
97-
vm.StartGraphicApplication(960, 600)
97+
vm.StartGraphicApplication(960, 600, vz.WithWindowTitle("Linux"), vz.WithController(true))
9898
runtime.UnlockOSThread()
9999

100100
cleanup()

virtualization_view.m

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N
285285
} else {
286286
[self hideOverlay];
287287
}
288+
// Terminating GUI Application from Guest and Host.
289+
// See: https://github.com/Code-Hex/vz/issues/150
290+
if (newState == VZVirtualMachineStateStopped) {
291+
[NSApp terminate:nil];
292+
}
288293
});
289294
}
290295
}
@@ -368,7 +373,7 @@ - (void)setToolBarItems:(NSArray<NSToolbarItemIdentifier> *)desiredItems
368373
/* IMPORTANT: delegate methods are called from VM's queue */
369374
- (void)guestDidStopVirtualMachine:(VZVirtualMachine *)virtualMachine
370375
{
371-
[NSApp performSelectorOnMainThread:@selector(terminate:) withObject:self waitUntilDone:NO];
376+
// [NSApp performSelectorOnMainThread:@selector(terminate:) withObject:self waitUntilDone:NO];
372377
}
373378

374379
- (void)virtualMachine:(VZVirtualMachine *)virtualMachine didStopWithError:(NSError *)error

0 commit comments

Comments
 (0)