From 3b4d6ce6df502270f966517da974a0d5b267bee4 Mon Sep 17 00:00:00 2001 From: Elijah R Date: Wed, 10 Apr 2024 19:03:17 -0400 Subject: [PATCH] minor bugfix in screen scaling --- src/ts/protocol/CollabVMClient.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/ts/protocol/CollabVMClient.ts b/src/ts/protocol/CollabVMClient.ts index bdaa916..e7e670e 100644 --- a/src/ts/protocol/CollabVMClient.ts +++ b/src/ts/protocol/CollabVMClient.ts @@ -416,11 +416,15 @@ export default class CollabVMClient { } private onWindowResize(e: Event) { - var copyctx = (this.actualScreenSize.width !== this.canvasScale.width || this.actualScreenSize.height !== this.canvasScale.height) ? this.unscaledCanvas : this.canvas; - this.recalculateCanvasScale(this.actualScreenSize.width, this.actualScreenSize.height); - this.canvas.width = this.canvasScale.width; - this.canvas.height = this.canvasScale.height; - this.ctx.drawImage(copyctx, 0, 0, this.actualScreenSize.width, this.actualScreenSize.height, 0, 0, this.canvas.width, this.canvas.height); + var t = setTimeout(() => { + if (!this.connectedToVM) return; + var copyctx = (this.actualScreenSize.width !== this.canvasScale.width || this.actualScreenSize.height !== this.canvasScale.height) ? this.unscaledCanvas : this.canvas; + this.recalculateCanvasScale(this.actualScreenSize.width, this.actualScreenSize.height); + this.canvas.width = this.canvasScale.width; + this.canvas.height = this.canvasScale.height; + this.ctx.drawImage(copyctx, 0, 0, this.actualScreenSize.width, this.actualScreenSize.height, 0, 0, this.canvas.width, this.canvas.height); + }, 500); + window.addEventListener('resize', () => clearTimeout(t), {once: true}); } private recalculateCanvasScale(width: number, height: number) {