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