2022-03-20 08:56:28 +00:00
|
|
|
import { Editor } from "./editor";
|
2022-04-25 17:46:08 +00:00
|
|
|
import { 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 () => {
|
|
|
|
// let localSpace = new Space(new IndexedDBSpacePrimitives("pages"), true);
|
|
|
|
// localSpace.watch();
|
|
|
|
let token: string | undefined = sessionStorage.getItem("token") || undefined;
|
2022-04-21 09:46:33 +00:00
|
|
|
|
2022-04-29 16:54:27 +00:00
|
|
|
let httpPrimitives = new HttpSpacePrimitives("", token);
|
|
|
|
while (true) {
|
|
|
|
try {
|
|
|
|
await httpPrimitives.getPageMeta("start");
|
|
|
|
break;
|
|
|
|
} catch (e: any) {
|
|
|
|
if (e.message === "Unauthorized") {
|
|
|
|
token = prompt("Token: ") || undefined;
|
|
|
|
if (!token) {
|
|
|
|
alert("Sorry, that's it then");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sessionStorage.setItem("token", token!);
|
|
|
|
httpPrimitives = new HttpSpacePrimitives("", token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let serverSpace = new Space(httpPrimitives, true);
|
|
|
|
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-04-29 16:54:27 +00:00
|
|
|
// // @ts-ignore
|
|
|
|
// window.syncer = async () => {
|
|
|
|
// let lastLocalSync = +(localStorage.getItem("lastLocalSync") || "0"),
|
|
|
|
// lastRemoteSync = +(localStorage.getItem("lastRemoteSync") || "0");
|
|
|
|
// let syncer = new SpaceSync(
|
|
|
|
// serverSpace,
|
|
|
|
// localSpace,
|
|
|
|
// lastRemoteSync,
|
|
|
|
// lastLocalSync,
|
|
|
|
// "_trash/"
|
|
|
|
// );
|
|
|
|
// await syncer.syncPages(
|
|
|
|
// SpaceSync.primaryConflictResolver(serverSpace, localSpace)
|
|
|
|
// );
|
|
|
|
// localStorage.setItem("lastLocalSync", "" + syncer.secondaryLastSync);
|
|
|
|
// localStorage.setItem("lastRemoteSync", "" + syncer.primaryLastSync);
|
|
|
|
// console.log("Done!");
|
|
|
|
// };
|
|
|
|
let editor = new Editor(serverSpace, document.getElementById("root")!);
|
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) {
|
|
|
|
// if (localStorage.getItem("disable_sw") !== "true") {
|
|
|
|
navigator.serviceWorker
|
|
|
|
.register(new URL("service_worker.ts", import.meta.url), { type: "module" })
|
|
|
|
.then((r) => {
|
|
|
|
console.log("Service worker registered...");
|
|
|
|
});
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|