forked from tools/josh
1
0
Fork 0

Update some documentation and such

This commit is contained in:
Florine W. Dekker 2021-03-31 17:34:32 +02:00
parent b75d66b7a2
commit 14188b0513
Signed by: FWDekker
GPG Key ID: B1B567AF58D6EE0F
3 changed files with 29 additions and 13 deletions

View File

@ -8,6 +8,11 @@ import {HashProvider, User} from "./UserList";
* A file system.
*/
export class FileSystem {
/**
* The root of the directory structure defined by the navigation API of fwdekker.com.
*
* This value is initialized only if `Persistence.hasFileSystem` returns false when the application is loaded.
*/
static navRoot: Directory;
/**
* The root directory.

View File

@ -22,7 +22,7 @@ declare global {
/**
* Compares version numbers to ensure no compatibility errors ensure.
* Compares version numbers to ensure no compatibility errors ensue.
*/
addOnLoad(() => {
const userVersion = Persistence.getVersion();
@ -30,15 +30,15 @@ addOnLoad(() => {
if (semver.lt(userVersion, latestVersion)) {
Persistence.reset();
Persistence.setWasUpdated(true); // Message is displayed after reload
Persistence.setWasUpdated(true); // Message is displayed after reload
location.reload(true);
throw new ExpectedGoodbyeError("Goodbye");
}
if (Persistence.getWasUpdated()) {
q("#terminalOutput").innerHTML = "" +
"<span style=\"color:red\">This website has been updated. To prevent unexpected errors, all previous " +
"user changes have been reset.</span>\n\n";
"<span style=\"color:red\">The terminal application has been updated. To prevent unexpected errors, all " +
"previous user changes have been reset.</span>\n\n";
Persistence.setWasUpdated(false);
}
@ -49,11 +49,11 @@ addOnLoad(() => {
* Exits the application if the server is "shut down".
*/
addOnLoad(() => {
if (Persistence.getPoweroff()) {
q("#terminalOutput").innerText = "Could not connect to fwdekker.com. Retrying in 10 seconds.";
setTimeout(() => location.reload(), 10000);
throw new ExpectedGoodbyeError("Goodbye");
}
if (!Persistence.getPoweroff()) return;
q("#terminalOutput").innerText = "Could not connect to fwdekker.com. Retrying in 10 seconds.";
setTimeout(() => location.reload(), 10000);
throw new ExpectedGoodbyeError("Goodbye");
});
/**
@ -72,7 +72,7 @@ addOnLoad(async () => {
);
window.execute = (command: string) => window.terminal.processInput(command);
// @ts-ignore: Ugly hack to execute it anyway
// @ts-ignore: Ugly hack to check if user is logged in
if (window.terminal.shell.environment.get("user") !== "")
window.execute("ls -l");
});

View File

@ -38,6 +38,8 @@ export class Persistence {
/**
* Deserializes a file system from persistent storage, or returns the default file system if the deserialization
* failed.
*
* @return the deserialized file system from persistent storage
*/
static getFileSystem(): FileSystem {
const fileString = localStorage.getItem("//files");
@ -67,6 +69,8 @@ export class Persistence {
/**
* Deserializes a history from persistent storage, or returns the default history if the deserialization failed.
*
* @return the deserialized history from persistent storage
*/
static getHistory(): InputHistory {
try {
@ -87,16 +91,18 @@ export class Persistence {
}
/**
* Returns the version of the scripts that were used the last time the user visited the website.
* Returns the version number of the scripts that were used the last time the user visited the website.
*
* @return the version number from persistent storage
*/
static getVersion(): string {
return localStorage.getItem("//version") ?? "%%VERSION_NUMBER%%";
}
/**
* Sets the version of the scripts that were used the last time the user visited the website.
* Sets the version number of the scripts that were used the last time the user visited the website.
*
* @param version the version of the scripts that were used the last time the user visited the website
* @param version the version number of the scripts that were used the last time the user visited the website
*/
static setVersion(version: string) {
localStorage.setItem("//version", version);
@ -109,6 +115,8 @@ export class Persistence {
/**
* Returns `true` if and only if the server is "turned off".
*
* @return `true` if and only if the server is "turned off"
*/
static getPoweroff(): boolean {
try {
@ -138,6 +146,7 @@ export class Persistence {
* failed.
*
* @param userList the list of users used to validate the `user` environment variable
* @return the deserialized environment from persistent storage
*/
static getEnvironment(userList: UserList): Environment {
const environmentString = sessionStorage.getItem("//env") ?? "{}";
@ -182,6 +191,8 @@ export class Persistence {
/**
* Returns `true` if and only if the terminal was updated in this session.
*
* @return `true` if and only if the terminal was updated in this session
*/
static getWasUpdated(): boolean {
try {