2022-03-20 08:56:28 +00:00
|
|
|
import { Editor } from "./editor";
|
|
|
|
import { safeRun } from "./util";
|
2022-04-08 15:46:09 +00:00
|
|
|
import { Space } from "../common/spaces/space";
|
|
|
|
import { HttpSpacePrimitives } from "../common/spaces/http_space_primitives";
|
|
|
|
import { IndexedDBSpacePrimitives } from "../common/spaces/indexeddb_space_primitives";
|
|
|
|
import { SpaceSync } from "../common/spaces/sync";
|
2022-03-20 08:56:28 +00:00
|
|
|
|
2022-04-07 13:21:30 +00:00
|
|
|
let localSpace = new Space(new IndexedDBSpacePrimitives("pages"), true);
|
2022-04-07 12:04:50 +00:00
|
|
|
localSpace.watch();
|
2022-04-07 13:21:30 +00:00
|
|
|
let serverSpace = new Space(new HttpSpacePrimitives(""), true);
|
|
|
|
serverSpace.watch();
|
2022-04-06 13:39:20 +00:00
|
|
|
|
|
|
|
// @ts-ignore
|
2022-04-07 12:04:50 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
navigator.serviceWorker
|
|
|
|
.register(new URL("service_worker.ts", import.meta.url), { type: "module" })
|
|
|
|
.then((r) => {
|
2022-03-21 14:21:34 +00:00
|
|
|
// console.log("Service worker registered", r);
|
2022-03-20 08:56:28 +00:00
|
|
|
});
|