diff --git a/package.json b/package.json index 85f347c..397fcc7 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/main/js/Main.ts b/src/main/js/Main.ts index 95d4944..a6c0ce1 100644 --- a/src/main/js/Main.ts +++ b/src/main/js/Main.ts @@ -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"), diff --git a/src/main/js/Persistence.ts b/src/main/js/Persistence.ts index 56b9427..217b159 100644 --- a/src/main/js/Persistence.ts +++ b/src/main/js/Persistence.ts @@ -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": "/" });