forked from tools/josh
1
0
Fork 0

Fix poweroff if no server is available

Fixes #94.
This commit is contained in:
Florine W. Dekker 2019-11-21 11:09:38 +01:00
parent b8dc83b960
commit 0c8e22e6e2
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 24 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "fwdekker.com", "name": "fwdekker.com",
"version": "0.21.2", "version": "0.21.3",
"description": "The source code of [my personal website](https://fwdekker.com/).", "description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker", "author": "Felix W. Dekker",
"repository": { "repository": {

View File

@ -1,3 +1,4 @@
import {Persistence} from "./Persistence";
import {addOnLoad, q} from "./Shared"; import {addOnLoad, q} from "./Shared";
import {Terminal} from "./Terminal"; import {Terminal} from "./Terminal";
@ -19,6 +20,12 @@ declare global {
addOnLoad(() => { addOnLoad(() => {
if (Persistence.getPoweroff()) {
q("#terminalOutput").innerText = "Could not connect to fwdekker.com. Retrying in 10 seconds.";
setTimeout(() => location.reload(), 10000);
return;
}
window.terminal = new Terminal( window.terminal = new Terminal(
q("#terminal"), q("#terminal"),
q("#terminalCurrentFocusInput"), q("#terminalCurrentFocusInput"),

View File

@ -68,9 +68,9 @@ export class Persistence {
if (parsedFiles instanceof Directory) if (parsedFiles instanceof Directory)
return new FileSystem(parsedFiles); return new FileSystem(parsedFiles);
else else
console.warn("`files` cookie contains non-directory."); console.warn("'files' cookie contains non-directory.");
} catch (error) { } catch (error) {
console.warn("Failed to deserialize `files` cookie.", error); console.warn("Failed to deserialize 'files' cookie.", error);
} }
} }
@ -93,7 +93,7 @@ export class Persistence {
try { try {
return new InputHistory(JSON.parse(localStorage.getItem("history") ?? "[]")); return new InputHistory(JSON.parse(localStorage.getItem("history") ?? "[]"));
} catch (error) { } catch (error) {
console.warn("Failed to deserialize `history` cookie.", error); console.warn("Failed to deserialize 'history' cookie.", error);
return new InputHistory(); return new InputHistory();
} }
} }
@ -107,13 +107,25 @@ export class Persistence {
localStorage.setItem("history", JSON.stringify(history.entries)); localStorage.setItem("history", JSON.stringify(history.entries));
} }
/**
* Returns the persisted "power off" setting.
*/
static getPoweroff(): boolean {
try {
return JSON.parse(Cookies.get("poweroff") ?? "false");
} catch(error) {
console.warn("Failed to deserialize 'poweroff' cookie.", error);
return false;
}
}
/** /**
* Persists the "power off" setting. * Persists the "power off" setting.
* *
* @param value the value to persist for the "power off" setting * @param value the value to persist for the "power off" setting
*/ */
static setPoweroff(value: boolean): void { static setPoweroff(value: boolean): void {
Cookies.set("poweroff", `${value}`, { Cookies.set("poweroff", "" + value, {
"expires": new Date(new Date().setSeconds(new Date().getSeconds() + 30)), "expires": new Date(new Date().setSeconds(new Date().getSeconds() + 30)),
"path": "/" "path": "/"
}); });