From 048f08b00b70b6f06da2ae9011b292e5cf69c7c9 Mon Sep 17 00:00:00 2001 From: modeco80 Date: Wed, 10 Jul 2024 18:43:35 -0400 Subject: [PATCH] actually make vm swich displays properly or whatever --- cvmts/src/CollabVMServer.ts | 12 ++++++++++-- qemu/src/QemuVM.ts | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/cvmts/src/CollabVMServer.ts b/cvmts/src/CollabVMServer.ts index 12f220f..0607221 100644 --- a/cvmts/src/CollabVMServer.ts +++ b/cvmts/src/CollabVMServer.ts @@ -113,14 +113,22 @@ export default class CollabVMServer { this.OnDisplayResized(initSize); - vm.GetDisplay().on('resize', (size: Size) => this.OnDisplayResized(size)); - vm.GetDisplay().on('rect', (rect: Rect) => this.OnDisplayRectangle(rect)); +// vm.GetDisplay().on('resize', (size: Size) => this.OnDisplayResized(size)); +// vm.GetDisplay().on('rect', (rect: Rect) => this.OnDisplayRectangle(rect)); this.VM = vm; // hack but whatever (TODO: less rickity) if (config.vm.type == 'qemu') { (vm as QemuVM).on('statechange', (newState: VMState) => { + if(newState == VMState.Started) { + this.logger.Info("started!!"); + + // well aware this sucks but whatever + this.VM.GetDisplay().on('resize', (size: Size) => this.OnDisplayResized(size)); + this.VM.GetDisplay().on('rect', (rect: Rect) => this.OnDisplayRectangle(rect)); + } + if (newState == VMState.Stopped) { this.logger.Info('stopped ?'); setTimeout(async () => { diff --git a/qemu/src/QemuVM.ts b/qemu/src/QemuVM.ts index 032f018..34dffc8 100644 --- a/qemu/src/QemuVM.ts +++ b/qemu/src/QemuVM.ts @@ -37,7 +37,7 @@ export class QemuVM extends EventEmitter { private qemuProcess: ExecaChildProcess | null = null; - private display: QemuDisplay; + private display: QemuDisplay | null; private definition: QemuVmDefinition; private addedAdditionalArguments = false; @@ -137,7 +137,7 @@ export class QemuVM extends EventEmitter { } GetDisplay() { - return this.display; + return this.display!; } /// Private fun bits :) @@ -260,6 +260,7 @@ export class QemuVM extends EventEmitter { self.qmpInstance.on('close', onQmpError); self.qmpInstance.on('error', (e: Error) => { self.VMLog().Error("QMP Error: {0}", e.message); + onQmpError(); }); self.qmpInstance.on('event', async (ev) => { @@ -277,7 +278,7 @@ export class QemuVM extends EventEmitter { self.qmpInstance.on('qmp-ready', async (hadError) => { self.VMLog().Info('QMP ready'); - self.display.Connect(); + self.display?.Connect(); // QMP has been connected so the VM is ready to be considered started self.qmpFailCount = 0; @@ -299,6 +300,9 @@ export class QemuVM extends EventEmitter { private async DisconnectDisplay() { try { this.display?.Disconnect(); + + // create a new display (and gc the old one) + this.display = new QemuDisplay(this.GetVncPath()); } catch (err) { // oh well lol }