From 1d900b518453ebb838fdba7aca2ca51ed4216856 Mon Sep 17 00:00:00 2001 From: Bruno Windels <274386+bwindels@users.noreply.github.com> Date: Tue, 10 May 2022 12:14:09 +0200 Subject: [PATCH] finish open window and poll code for logviewer --- .../web/ui/session/settings/SettingsView.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/platform/web/ui/session/settings/SettingsView.js b/src/platform/web/ui/session/settings/SettingsView.js index e07aaff5..09d3cb5a 100644 --- a/src/platform/web/ui/session/settings/SettingsView.js +++ b/src/platform/web/ui/session/settings/SettingsView.js @@ -146,18 +146,24 @@ async function openLogs(vm) { const logviewerUrl = (await import("../../../../../../scripts/logviewer/index.html?url")).default; const win = window.open(logviewerUrl); await new Promise((resolve, reject) => { - let receivedPong = false; + let shouldSendPings = true; + const cleanup = () => { + shouldSendPings = false; + window.removeEventListener("message", waitForPong); + }; const waitForPong = event => { if (event.data.type === "pong") { - window.removeEventListener("message", waitForPong); - receivedPong = true; + cleanup(); resolve(); } }; const sendPings = async () => { - while (!receivedPong) { + while (shouldSendPings) { win.postMessage({type: "ping"}); - await new Promise(rr => setTimeout(rr), 100); + await new Promise(rr => setTimeout(rr, 50)); + if (win.closed) { + cleanup(); + } } }; window.addEventListener("message", waitForPong);