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",
"version": "0.21.2",
"version": "0.21.3",
"description": "The source code of [my personal website](https://fwdekker.com/).",
"author": "Felix W. Dekker",
"repository": {

View File

@ -1,3 +1,4 @@
import {Persistence} from "./Persistence";
import {addOnLoad, q} from "./Shared";
import {Terminal} from "./Terminal";
@ -19,6 +20,12 @@ declare global {
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(
q("#terminal"),
q("#terminalCurrentFocusInput"),

View File

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