cvmts: fix display event handler duplication

By only adding event handlers when the display is first lazily initalized.
This commit is contained in:
modeco80
2024-09-19 04:11:25 -04:00
parent 210e36f430
commit 072fd06918

View File

@@ -129,17 +129,17 @@ export default class CollabVMServer {
if (newState == VMState.Started) { if (newState == VMState.Started) {
self.logger.info('VM started'); self.logger.info('VM started');
// start the display // start the display and add the events once
if (self.VM.GetDisplay() == null) { if (self.VM.GetDisplay() == null) {
self.VM.StartDisplay(); self.VM.StartDisplay();
}
self.VM.GetDisplay()?.on('connected', () => { self.logger.info('started display, adding events now');
// well aware this sucks but whatever
// add events
self.VM.GetDisplay()?.on('resize', (size: Size) => self.OnDisplayResized(size)); self.VM.GetDisplay()?.on('resize', (size: Size) => self.OnDisplayResized(size));
self.VM.GetDisplay()?.on('rect', (rect: Rect) => self.OnDisplayRectangle(rect)); self.VM.GetDisplay()?.on('rect', (rect: Rect) => self.OnDisplayRectangle(rect));
self.VM.GetDisplay()?.on('frame', () => self.OnDisplayFrame()); self.VM.GetDisplay()?.on('frame', () => self.OnDisplayFrame());
}); }
} }
if (newState == VMState.Stopped) { if (newState == VMState.Stopped) {