2020-03-24 20:48:57 +01:00
|
|
|
import * as semver from "semver";
|
2021-04-22 16:19:15 +02:00
|
|
|
// @ts-ignore
|
|
|
|
const {$, doAfterLoad, nav} = window.fwdekker;
|
2020-09-30 14:53:18 +02:00
|
|
|
import {FileSystem} from "./FileSystem";
|
2019-11-21 11:09:38 +01:00
|
|
|
import {Persistence} from "./Persistence";
|
2021-04-22 16:19:15 +02:00
|
|
|
import {ExpectedGoodbyeError} from "./Shared";
|
2019-11-01 11:59:33 +01:00
|
|
|
import {Terminal} from "./Terminal";
|
2019-10-27 01:22:23 +02:00
|
|
|
|
|
|
|
|
2019-10-31 23:22:37 +01:00
|
|
|
declare global {
|
|
|
|
interface Window {
|
|
|
|
/**
|
|
|
|
* The main terminal.
|
|
|
|
*/
|
|
|
|
terminal: Terminal
|
|
|
|
/**
|
|
|
|
* Executes a command in the main terminal.
|
|
|
|
*
|
|
|
|
* @param command the command to execute
|
|
|
|
*/
|
|
|
|
execute: (command: string) => void
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-12-01 23:31:03 +01:00
|
|
|
/**
|
2021-03-31 17:34:32 +02:00
|
|
|
* Compares version numbers to ensure no compatibility errors ensue.
|
2019-12-01 23:31:03 +01:00
|
|
|
*/
|
2021-04-22 16:19:15 +02:00
|
|
|
doAfterLoad(() => {
|
2019-12-01 23:31:03 +01:00
|
|
|
const userVersion = Persistence.getVersion();
|
|
|
|
const latestVersion = "%%VERSION_NUMBER%%";
|
|
|
|
|
|
|
|
if (semver.lt(userVersion, latestVersion)) {
|
|
|
|
Persistence.reset();
|
2021-03-31 17:34:32 +02:00
|
|
|
Persistence.setWasUpdated(true); // Message is displayed after reload
|
2020-01-21 18:09:43 +01:00
|
|
|
location.reload(true);
|
2019-12-01 23:31:03 +01:00
|
|
|
throw new ExpectedGoodbyeError("Goodbye");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Persistence.getWasUpdated()) {
|
2021-04-22 16:19:15 +02:00
|
|
|
$("#terminalOutput").innerHTML = "" +
|
2021-04-24 22:29:23 +02:00
|
|
|
"<span class=\"errorMessage\">The terminal application has been updated. To prevent unexpected errors, " +
|
|
|
|
"all previous user changes have been reset.</span>\n\n";
|
2019-12-01 23:31:03 +01:00
|
|
|
Persistence.setWasUpdated(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Persistence.setVersion(latestVersion);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2020-03-18 16:44:16 +01:00
|
|
|
* Exits the application if the server is "shut down".
|
2019-12-01 23:31:03 +01:00
|
|
|
*/
|
2021-04-22 16:19:15 +02:00
|
|
|
doAfterLoad(() => {
|
2021-03-31 17:34:32 +02:00
|
|
|
if (!Persistence.getPoweroff()) return;
|
|
|
|
|
2021-04-22 16:19:15 +02:00
|
|
|
$("#terminalOutput").innerText = "Could not connect to fwdekker.com. Retrying in 10 seconds.";
|
2021-03-31 17:34:32 +02:00
|
|
|
setTimeout(() => location.reload(), 10000);
|
|
|
|
throw new ExpectedGoodbyeError("Goodbye");
|
2019-12-01 23:31:03 +01:00
|
|
|
});
|
2019-11-21 11:09:38 +01:00
|
|
|
|
2019-12-01 23:31:03 +01:00
|
|
|
/**
|
|
|
|
* Initializes the application.
|
|
|
|
*/
|
2021-04-22 16:19:15 +02:00
|
|
|
doAfterLoad(async () => {
|
|
|
|
$("#nav").appendChild(nav("/"));
|
2021-03-31 17:31:42 +02:00
|
|
|
if (!Persistence.hasFileSystem())
|
|
|
|
await FileSystem.loadNavApi();
|
2020-09-30 14:53:18 +02:00
|
|
|
|
2019-10-27 01:22:23 +02:00
|
|
|
window.terminal = new Terminal(
|
2021-04-22 16:19:15 +02:00
|
|
|
$("#terminal"),
|
|
|
|
$("#terminalInputField"),
|
|
|
|
$("#terminalOutput"),
|
|
|
|
$("#terminalInputPrefix"),
|
|
|
|
$("#terminalSuggestions")
|
2019-10-27 01:22:23 +02:00
|
|
|
);
|
2019-10-31 23:22:37 +01:00
|
|
|
window.execute = (command: string) => window.terminal.processInput(command);
|
2019-10-27 01:22:23 +02:00
|
|
|
|
2021-03-31 17:34:32 +02:00
|
|
|
// @ts-ignore: Ugly hack to check if user is logged in
|
2019-11-06 14:02:18 +01:00
|
|
|
if (window.terminal.shell.environment.get("user") !== "")
|
2020-09-30 16:50:45 +02:00
|
|
|
window.execute("ls -l");
|
2019-10-27 01:22:23 +02:00
|
|
|
});
|