Show Connecting..Authenticating...Executing... status.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3406 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2017-05-22 19:38:49 +00:00
parent bbf980b672
commit db6467187d

View File

@ -13,6 +13,9 @@ var gBackup;
var kMaxCommandHistory = 16; var kMaxCommandHistory = 16;
var kErrorColor = "#dc322f";
var kStatusColor = "#fff";
window.addEventListener("keydown", function(event) { window.addEventListener("keydown", function(event) {
if (event.keyCode == 69 && event.altKey) { if (event.keyCode == 69 && event.altKey) {
if (!editing()) { if (!editing()) {
@ -332,9 +335,11 @@ function receive(data) {
if (line && line.action == "ping") { if (line && line.action == "ping") {
gSocket.send(JSON.stringify({action: "pong"})); gSocket.send(JSON.stringify({action: "pong"}));
} else if (line && line.action == "session") { } else if (line && line.action == "session") {
setStatusMessage("...Executing...", kStatusColor, true);
gCredentials = line.credentials; gCredentials = line.credentials;
updateLogin(); updateLogin();
} else if (line && line[0] && line[0].action == "ready") { } else if (line && line[0] && line[0].action == "ready") {
setStatusMessage(null);
if (window.location.hash) { if (window.location.hash) {
send({event: "hashChange", hash: window.location.hash}); send({event: "hashChange", hash: window.location.hash});
} }
@ -580,14 +585,16 @@ function autoScroll(terminal) {
terminal.scrollTop = terminal.scrollHeight - terminal.clientHeight; terminal.scrollTop = terminal.scrollHeight - terminal.clientHeight;
} }
function setErrorMessage(message) { function setStatusMessage(message, color, keep) {
var node = document.getElementById("status"); var node = document.getElementById("status");
while (node.firstChild) { if (!keep) {
node.removeChild(node.firstChild); while (node.firstChild) {
node.removeChild(node.firstChild);
}
} }
if (message) { if (message) {
node.appendChild(document.createTextNode(message)); node.appendChild(document.createTextNode(message));
node.setAttribute("style", "display: inline; color: #dc322f"); node.setAttribute("style", "display: inline; color: " + (color || kErrorColor));
} }
} }
@ -600,7 +607,7 @@ function send(command) {
try { try {
gSocket.send(JSON.stringify({action: "command", command: value})); gSocket.send(JSON.stringify({action: "command", command: value}));
} catch (error) { } catch (error) {
setErrorMessage("Send failed: " + error.toString()); setStatusMessage("Send failed: " + error.toString(), kErrorColor);
} }
} }
@ -787,13 +794,14 @@ function reconnect() {
function connectSocket() { function connectSocket() {
if (!gSocket || gSocket.readyState == gSocket.CLOSED) { if (!gSocket || gSocket.readyState == gSocket.CLOSED) {
setStatusMessage("Connecting...", kStatusColor, true);
gSocket = new WebSocket( gSocket = new WebSocket(
(window.location.protocol == "https:" ? "wss://" : "ws://") (window.location.protocol == "https:" ? "wss://" : "ws://")
+ window.location.hostname + window.location.hostname
+ (window.location.port.length ? ":" + window.location.port : "") + (window.location.port.length ? ":" + window.location.port : "")
+ "/terminal/socket"); + "/terminal/socket");
gSocket.onopen = function() { gSocket.onopen = function() {
setErrorMessage(null); setStatusMessage("...Authenticating...", kStatusColor, true);
gSocket.send(JSON.stringify({ gSocket.send(JSON.stringify({
action: "hello", action: "hello",
path: window.location.pathname, path: window.location.pathname,
@ -823,7 +831,7 @@ function connectSocket() {
receive(JSON.parse(event.data)); receive(JSON.parse(event.data));
} }
gSocket.onclose = function(event) { gSocket.onclose = function(event) {
setErrorMessage("Connection closed with code " + event.code); setStatusMessage("Connection closed with code " + event.code, kErrorColor);
} }
} }
} }