2022-03-20 08:56:28 +00:00
|
|
|
import { Editor } from "./editor";
|
2022-08-02 10:43:39 +00:00
|
|
|
import { parseYamlSettings, safeRun } from "@silverbulletmd/common/util";
|
2022-04-21 11:57:45 +00:00
|
|
|
import { Space } from "@silverbulletmd/common/spaces/space";
|
|
|
|
import { HttpSpacePrimitives } from "@silverbulletmd/common/spaces/http_space_primitives";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-29 16:54:27 +00:00
|
|
|
safeRun(async () => {
|
2022-06-28 12:14:15 +00:00
|
|
|
let password: string | undefined =
|
|
|
|
localStorage.getItem("password") || undefined;
|
2022-04-21 09:46:33 +00:00
|
|
|
|
2022-06-28 12:14:15 +00:00
|
|
|
let httpPrimitives = new HttpSpacePrimitives("", password);
|
2022-08-02 10:43:39 +00:00
|
|
|
let settingsPageText = "";
|
2022-04-29 16:54:27 +00:00
|
|
|
while (true) {
|
|
|
|
try {
|
2022-09-12 12:50:37 +00:00
|
|
|
settingsPageText = (await (
|
|
|
|
await httpPrimitives.readFile("SETTINGS.md", "string")
|
|
|
|
).data) as string;
|
2022-04-29 16:54:27 +00:00
|
|
|
break;
|
|
|
|
} catch (e: any) {
|
|
|
|
if (e.message === "Unauthorized") {
|
2022-06-28 12:14:15 +00:00
|
|
|
password = prompt("Password: ") || undefined;
|
|
|
|
if (!password) {
|
|
|
|
alert("Sorry, need a password");
|
2022-04-29 16:54:27 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-06-28 12:14:15 +00:00
|
|
|
localStorage.setItem("password", password!);
|
|
|
|
httpPrimitives = new HttpSpacePrimitives("", password);
|
2022-04-29 16:54:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-09-12 12:50:37 +00:00
|
|
|
let serverSpace = new Space(httpPrimitives);
|
2022-04-29 16:54:27 +00:00
|
|
|
serverSpace.watch();
|
2022-04-25 17:46:08 +00:00
|
|
|
|
2022-04-29 16:54:27 +00:00
|
|
|
console.log("Booting...");
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-08-02 10:43:39 +00:00
|
|
|
let settings = parseYamlSettings(settingsPageText);
|
|
|
|
|
|
|
|
let editor = new Editor(
|
|
|
|
serverSpace,
|
|
|
|
document.getElementById("sb-root")!,
|
|
|
|
"",
|
|
|
|
settings.indexPage || "index"
|
|
|
|
);
|
2022-03-20 08:56:28 +00:00
|
|
|
await editor.init();
|
2022-04-29 16:54:27 +00:00
|
|
|
// @ts-ignore
|
|
|
|
window.editor = editor;
|
2022-03-20 08:56:28 +00:00
|
|
|
});
|
|
|
|
|
2022-04-25 17:46:08 +00:00
|
|
|
// if (!isDesktop) {
|
2022-06-14 07:45:22 +00:00
|
|
|
if (localStorage.getItem("disable_sw") !== "true") {
|
|
|
|
if (navigator.serviceWorker) {
|
|
|
|
navigator.serviceWorker
|
|
|
|
.register(new URL("service_worker.ts", import.meta.url), {
|
|
|
|
type: "module",
|
|
|
|
})
|
|
|
|
.then((r) => {
|
|
|
|
console.log("Service worker registered...");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
"No launching service worker (not present, maybe because not running on localhost or over SSL)"
|
|
|
|
);
|
|
|
|
}
|
2022-05-04 14:09:39 +00:00
|
|
|
}
|
2022-04-25 17:46:08 +00:00
|
|
|
|
|
|
|
// }
|