2022-03-20 08:56:28 +00:00
|
|
|
import { Editor } from "./editor";
|
2022-04-21 12:16:40 +00:00
|
|
|
import { safeRun } from "../silverbullet-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-21 09:46:33 +00:00
|
|
|
// let localSpace = new Space(new IndexedDBSpacePrimitives("pages"), true);
|
|
|
|
// localSpace.watch();
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
let isDesktop = typeof window.desktop !== "undefined";
|
2022-04-06 13:39:20 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2022-04-21 09:46:33 +00:00
|
|
|
let url = isDesktop ? window.desktop.url : "";
|
|
|
|
|
|
|
|
let serverSpace = new Space(new HttpSpacePrimitives(url), true);
|
|
|
|
serverSpace.watch();
|
|
|
|
|
|
|
|
// // @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!");
|
|
|
|
// };
|
2022-04-07 13:21:30 +00:00
|
|
|
let editor = new Editor(serverSpace, document.getElementById("root")!);
|
2022-03-20 08:56:28 +00:00
|
|
|
|
|
|
|
safeRun(async () => {
|
|
|
|
await editor.init();
|
|
|
|
});
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
window.editor = editor;
|
|
|
|
|
2022-04-21 09:46:33 +00:00
|
|
|
if (!isDesktop) {
|
|
|
|
navigator.serviceWorker
|
|
|
|
.register(new URL("service_worker.ts", import.meta.url), { type: "module" })
|
|
|
|
.then((r) => {
|
|
|
|
// console.log("Service worker registered", r);
|
|
|
|
});
|
|
|
|
}
|