Spaces:
Sleeping
Sleeping
Commit ·
f2e8e3c
1
Parent(s): bba9027
fixed the double START pressing issue when getting out of the iFrame
Browse files- hf_server.js +41 -7
- test_iframe.html +12 -0
hf_server.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
* All rights reserved.
|
| 4 |
*/
|
| 5 |
//@ts-check
|
| 6 |
-
const VERSION = '0.6.0.hf.015.
|
| 7 |
|
| 8 |
const express = require('express');
|
| 9 |
const http = require('http');
|
|
@@ -104,7 +104,7 @@ const COMMON_STYLES = `
|
|
| 104 |
|
| 105 |
function startServer() {
|
| 106 |
document.getElementById('startServerButton').classList.remove
|
| 107 |
-
('highlight-button');
|
| 108 |
document.getElementById('startServerButton').disabled = true;
|
| 109 |
|
| 110 |
|
|
@@ -116,7 +116,15 @@ const COMMON_STYLES = `
|
|
| 116 |
}
|
| 117 |
|
| 118 |
function exitIframe() {
|
| 119 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
}
|
| 121 |
|
| 122 |
function refreshPage() {
|
|
@@ -133,8 +141,30 @@ const COMMON_STYLES = `
|
|
| 133 |
logContainer.innerText = data.logs.join("");
|
| 134 |
if (data.ready) {
|
| 135 |
|
|
|
|
| 136 |
document.getElementById('refreshButton').disabled = false;
|
| 137 |
document.getElementById('refreshButton').classList.add('highlight-button');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
}
|
| 140 |
else {
|
|
@@ -294,10 +324,10 @@ async function handleGetOmnitoolLogs(req, res)
|
|
| 294 |
|
| 295 |
async function handleGetBurstIframe(req, res)
|
| 296 |
{
|
| 297 |
-
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 298 |
req.session.isVisited = true;
|
| 299 |
|
| 300 |
const reply = { burst_iframe: true };
|
|
|
|
| 301 |
res.end(JSON.stringify(reply));
|
| 302 |
|
| 303 |
return;
|
|
@@ -324,7 +354,8 @@ async function proxyRequest(req, res)
|
|
| 324 |
async function handleGetRoot(req, res)
|
| 325 |
{
|
| 326 |
setGlobals(req);
|
| 327 |
-
|
|
|
|
| 328 |
console.log(`req.session.isVisited = ${req.session.isVisited}`);
|
| 329 |
console.log(`global.OMNITOOL_RUNNING = ${global.OMNITOOL_RUNNING}`);
|
| 330 |
|
|
@@ -356,6 +387,7 @@ async function handleGetRoot(req, res)
|
|
| 356 |
${COMMON_STYLES}
|
| 357 |
</head>
|
| 358 |
<body>
|
|
|
|
| 359 |
${INTRO_MESSAGE}
|
| 360 |
${page_message}
|
| 361 |
<p></p>
|
|
@@ -390,6 +422,7 @@ async function handleGetRoot(req, res)
|
|
| 390 |
${COMMON_STYLES}
|
| 391 |
</head>
|
| 392 |
<body>
|
|
|
|
| 393 |
${INTRO_MESSAGE}
|
| 394 |
${page_message}
|
| 395 |
<p></p>
|
|
@@ -410,11 +443,11 @@ async function handleGetRoot(req, res)
|
|
| 410 |
page_message += `<div>It looks like Omnitool is not running on this Space. Let's fix that.</div><div>Press the [LAUNCH] button below.</div><div>Once Omnitool is running, you will be able to access it by pressing the [REFRESH] button.</div>`;
|
| 411 |
|
| 412 |
console.log('Omnitool server is not running');
|
| 413 |
-
const startButtonClass = 'highlight-button';
|
| 414 |
|
| 415 |
let buttonsHTML = `
|
| 416 |
<button id="startServerButton" class="${startButtonClass}" onclick="startServer()">LAUNCH</button>
|
| 417 |
-
<button id="refreshButton" class="${''}" onclick="refreshPage()">REFRESH</button>
|
| 418 |
`;
|
| 419 |
|
| 420 |
const page_html = `
|
|
@@ -424,6 +457,7 @@ async function handleGetRoot(req, res)
|
|
| 424 |
${COMMON_STYLES}
|
| 425 |
</head>
|
| 426 |
<body>
|
|
|
|
| 427 |
${INTRO_MESSAGE}
|
| 428 |
${page_message}
|
| 429 |
<p></p>
|
|
|
|
| 3 |
* All rights reserved.
|
| 4 |
*/
|
| 5 |
//@ts-check
|
| 6 |
+
const VERSION = '0.6.0.hf.015.b';
|
| 7 |
|
| 8 |
const express = require('express');
|
| 9 |
const http = require('http');
|
|
|
|
| 104 |
|
| 105 |
function startServer() {
|
| 106 |
document.getElementById('startServerButton').classList.remove
|
| 107 |
+
('highlight-button-green');
|
| 108 |
document.getElementById('startServerButton').disabled = true;
|
| 109 |
|
| 110 |
|
|
|
|
| 116 |
}
|
| 117 |
|
| 118 |
function exitIframe() {
|
| 119 |
+
if (window.self !== window.top)
|
| 120 |
+
{
|
| 121 |
+
// open a new window to get out of the iframe, then wait 1s, then fetch burst-iframe then reload
|
| 122 |
+
window.open(window.location.href+"?isVisited=true", '_blank');
|
| 123 |
+
}
|
| 124 |
+
else
|
| 125 |
+
{
|
| 126 |
+
fetch('/burst-iframe').then(response => response.json()).then(data => {window.location.reload();});
|
| 127 |
+
}
|
| 128 |
}
|
| 129 |
|
| 130 |
function refreshPage() {
|
|
|
|
| 141 |
logContainer.innerText = data.logs.join("");
|
| 142 |
if (data.ready) {
|
| 143 |
|
| 144 |
+
scrollToBottom(logContainer);
|
| 145 |
document.getElementById('refreshButton').disabled = false;
|
| 146 |
document.getElementById('refreshButton').classList.add('highlight-button');
|
| 147 |
+
clearInterval(interval);
|
| 148 |
+
|
| 149 |
+
}
|
| 150 |
+
else {
|
| 151 |
+
scrollToBottom(logContainer);
|
| 152 |
+
}
|
| 153 |
+
});
|
| 154 |
+
}, 500);
|
| 155 |
+
|
| 156 |
+
const interval2 = setInterval(() => {
|
| 157 |
+
fetch('/omnitool-logs')
|
| 158 |
+
.then(response => response.json())
|
| 159 |
+
.then(data => {
|
| 160 |
+
const logContainer = document.getElementById('logContainer');
|
| 161 |
+
logContainer.innerText = data.logs.join("");
|
| 162 |
+
if (data.ready) {
|
| 163 |
+
|
| 164 |
+
scrollToBottom(logContainer);
|
| 165 |
+
document.getElementById('refreshButton').disabled = false;
|
| 166 |
+
document.getElementById('refreshButton').classList.add('highlight-button');
|
| 167 |
+
clearInterval(interval);
|
| 168 |
|
| 169 |
}
|
| 170 |
else {
|
|
|
|
| 324 |
|
| 325 |
async function handleGetBurstIframe(req, res)
|
| 326 |
{
|
|
|
|
| 327 |
req.session.isVisited = true;
|
| 328 |
|
| 329 |
const reply = { burst_iframe: true };
|
| 330 |
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
| 331 |
res.end(JSON.stringify(reply));
|
| 332 |
|
| 333 |
return;
|
|
|
|
| 354 |
async function handleGetRoot(req, res)
|
| 355 |
{
|
| 356 |
setGlobals(req);
|
| 357 |
+
if (req.query.isVisited) req.session.isVisited = true;
|
| 358 |
+
|
| 359 |
console.log(`req.session.isVisited = ${req.session.isVisited}`);
|
| 360 |
console.log(`global.OMNITOOL_RUNNING = ${global.OMNITOOL_RUNNING}`);
|
| 361 |
|
|
|
|
| 387 |
${COMMON_STYLES}
|
| 388 |
</head>
|
| 389 |
<body>
|
| 390 |
+
<div>req.session.isVisited = ${req.session.isVisited}</div>
|
| 391 |
${INTRO_MESSAGE}
|
| 392 |
${page_message}
|
| 393 |
<p></p>
|
|
|
|
| 422 |
${COMMON_STYLES}
|
| 423 |
</head>
|
| 424 |
<body>
|
| 425 |
+
<div>req.session.isVisited = ${req.session.isVisited}</div>
|
| 426 |
${INTRO_MESSAGE}
|
| 427 |
${page_message}
|
| 428 |
<p></p>
|
|
|
|
| 443 |
page_message += `<div>It looks like Omnitool is not running on this Space. Let's fix that.</div><div>Press the [LAUNCH] button below.</div><div>Once Omnitool is running, you will be able to access it by pressing the [REFRESH] button.</div>`;
|
| 444 |
|
| 445 |
console.log('Omnitool server is not running');
|
| 446 |
+
const startButtonClass = 'highlight-button-green';
|
| 447 |
|
| 448 |
let buttonsHTML = `
|
| 449 |
<button id="startServerButton" class="${startButtonClass}" onclick="startServer()">LAUNCH</button>
|
| 450 |
+
<button id="refreshButton" class="${''}" disabled onclick="refreshPage()">REFRESH</button>
|
| 451 |
`;
|
| 452 |
|
| 453 |
const page_html = `
|
|
|
|
| 457 |
${COMMON_STYLES}
|
| 458 |
</head>
|
| 459 |
<body>
|
| 460 |
+
<div>req.session.isVisited = ${req.session.isVisited}</div>
|
| 461 |
${INTRO_MESSAGE}
|
| 462 |
${page_message}
|
| 463 |
<p></p>
|
test_iframe.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Test Page</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<iframe src="http://localhost:4444" width="100%" height="600px">
|
| 8 |
+
<!-- Fallback content for browsers that don't support iframes -->
|
| 9 |
+
<p>Your browser does not support iframes.</p>
|
| 10 |
+
</iframe>
|
| 11 |
+
</body>
|
| 12 |
+
</html>
|