Skip to content

Commit 43aa1ab

Browse files
committed
fix(simulator): clear canvas and cancel background timers on resolution and template changes
1 parent 8b01d12 commit 43aa1ab

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

simulator/simulator.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,22 @@ except Exception:
305305
// Canvas Resolution & Device Presets
306306
// =========================================================================
307307

308+
function clearCanvas() {
309+
if (!elCanvas) return;
310+
const ctx = elCanvas.getContext("2d");
311+
if (ctx) {
312+
ctx.fillStyle = "#000000";
313+
ctx.fillRect(0, 0, elCanvas.width, elCanvas.height);
314+
}
315+
}
316+
308317
function setCanvasResolution(width, height, shape = "rectangle") {
309318
currentResolution = { width, height, shape };
310319
if (!elCanvas) return;
311320

312321
elCanvas.width = width;
313322
elCanvas.height = height;
323+
clearCanvas();
314324

315325
if (elDeviceBezel) {
316326
if (shape === "round") {
@@ -319,6 +329,24 @@ except Exception:
319329
elDeviceBezel.classList.remove("is-round");
320330
}
321331
}
332+
333+
// Stop active background timers when resolution or template changes
334+
if (pyodideInstance) {
335+
pyodideInstance.runPythonAsync(`
336+
import sys
337+
if "display_driver" in sys.modules:
338+
try:
339+
dd = sys.modules["display_driver"]
340+
if hasattr(dd, "event_loop"):
341+
inst = dd.event_loop.current_instance()
342+
if inst is not None:
343+
inst.deinit()
344+
if hasattr(dd, "app"):
345+
dd.app.stop_timer()
346+
except Exception:
347+
pass
348+
`).catch(() => {});
349+
}
322350
}
323351

324352
function handleResolutionChange(val) {

0 commit comments

Comments
 (0)