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();
|
2022-05-02 11:32:41 +00:00
|
|
|
let token: string | undefined = localStorage.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;
|
|
|
|
}
|
2022-05-02 11:32:41 +00:00
|
|
|
localStorage.setItem("token", token!);
|
2022-04-29 16:54:27 +00:00
|
|
|
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) {
|
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
|
|
|
|
|
|
|
// }
|