forked from mystiq/hydrogen-web
finish open window and poll code for logviewer
This commit is contained in:
parent
c823bb125f
commit
1d900b5184
1 changed files with 11 additions and 5 deletions
|
@ -146,18 +146,24 @@ async function openLogs(vm) {
|
||||||
const logviewerUrl = (await import("../../../../../../scripts/logviewer/index.html?url")).default;
|
const logviewerUrl = (await import("../../../../../../scripts/logviewer/index.html?url")).default;
|
||||||
const win = window.open(logviewerUrl);
|
const win = window.open(logviewerUrl);
|
||||||
await new Promise((resolve, reject) => {
|
await new Promise((resolve, reject) => {
|
||||||
let receivedPong = false;
|
let shouldSendPings = true;
|
||||||
|
const cleanup = () => {
|
||||||
|
shouldSendPings = false;
|
||||||
|
window.removeEventListener("message", waitForPong);
|
||||||
|
};
|
||||||
const waitForPong = event => {
|
const waitForPong = event => {
|
||||||
if (event.data.type === "pong") {
|
if (event.data.type === "pong") {
|
||||||
window.removeEventListener("message", waitForPong);
|
cleanup();
|
||||||
receivedPong = true;
|
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const sendPings = async () => {
|
const sendPings = async () => {
|
||||||
while (!receivedPong) {
|
while (shouldSendPings) {
|
||||||
win.postMessage({type: "ping"});
|
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);
|
window.addEventListener("message", waitForPong);
|
||||||
|
|
Loading…
Reference in a new issue