2022-10-10 12:50:21 +00:00
|
|
|
import { Editor } from "./editor.tsx";
|
|
|
|
import { parseYamlSettings, safeRun } from "../common/util.ts";
|
|
|
|
import { Space } from "../common/spaces/space.ts";
|
|
|
|
import { HttpSpacePrimitives } from "../common/spaces/http_space_primitives.ts";
|
2023-01-13 14:41:29 +00:00
|
|
|
import { PlugSpacePrimitives } from "../common/spaces/plug_space_primitives.ts";
|
|
|
|
import { PageNamespaceHook } from "../common/hooks/page_namespace.ts";
|
2022-11-24 11:04:00 +00:00
|
|
|
import { SilverBulletHooks } from "../common/manifest.ts";
|
|
|
|
import { System } from "../plugos/system.ts";
|
2022-12-15 12:23:49 +00:00
|
|
|
import { BuiltinSettings } from "./types.ts";
|
2023-01-08 11:24:12 +00:00
|
|
|
import { fulltextSyscalls } from "./syscalls/fulltext.ts";
|
|
|
|
import { indexerSyscalls } from "./syscalls/index.ts";
|
|
|
|
import { storeSyscalls } from "./syscalls/store.ts";
|
|
|
|
import { EventHook } from "../plugos/hooks/event.ts";
|
|
|
|
import { clientStoreSyscalls } from "./syscalls/clientStore.ts";
|
|
|
|
import { sandboxFetchSyscalls } from "./syscalls/fetch.ts";
|
2022-10-10 12:50:21 +00:00
|
|
|
|
|
|
|
safeRun(async () => {
|
2022-12-05 11:14:21 +00:00
|
|
|
const httpPrimitives = new HttpSpacePrimitives("");
|
2022-10-10 12:50:21 +00:00
|
|
|
let settingsPageText = "";
|
2022-12-05 11:14:21 +00:00
|
|
|
try {
|
|
|
|
settingsPageText = (
|
2023-01-13 14:41:29 +00:00
|
|
|
await httpPrimitives.readFile("SETTINGS.md", "utf8")
|
2022-12-05 11:14:21 +00:00
|
|
|
).data as string;
|
|
|
|
} catch (e: any) {
|
|
|
|
console.error("No settings page found", e.message);
|
2022-10-10 12:50:21 +00:00
|
|
|
}
|
2022-11-24 11:04:00 +00:00
|
|
|
|
|
|
|
// Instantiate a PlugOS system for the client
|
|
|
|
const system = new System<SilverBulletHooks>("client");
|
|
|
|
|
|
|
|
// Attach the page namespace hook
|
|
|
|
const namespaceHook = new PageNamespaceHook();
|
|
|
|
system.addHook(namespaceHook);
|
|
|
|
|
|
|
|
const spacePrimitives = new PlugSpacePrimitives(
|
|
|
|
httpPrimitives,
|
|
|
|
namespaceHook,
|
|
|
|
"client",
|
|
|
|
);
|
|
|
|
|
|
|
|
const serverSpace = new Space(spacePrimitives);
|
2022-10-10 12:50:21 +00:00
|
|
|
serverSpace.watch();
|
|
|
|
|
2023-01-08 11:24:12 +00:00
|
|
|
// Register some web-specific syscall implementations
|
|
|
|
system.registerSyscalls(
|
|
|
|
[],
|
|
|
|
storeSyscalls(serverSpace),
|
|
|
|
indexerSyscalls(serverSpace),
|
|
|
|
clientStoreSyscalls(),
|
|
|
|
fulltextSyscalls(serverSpace),
|
|
|
|
sandboxFetchSyscalls(serverSpace),
|
|
|
|
);
|
|
|
|
|
2022-10-10 12:50:21 +00:00
|
|
|
console.log("Booting...");
|
|
|
|
|
2022-12-15 12:23:49 +00:00
|
|
|
const settings = parseYamlSettings(settingsPageText) as BuiltinSettings;
|
|
|
|
|
|
|
|
if (!settings.indexPage) {
|
|
|
|
settings.indexPage = "index";
|
|
|
|
}
|
2023-01-08 11:24:12 +00:00
|
|
|
// Event hook
|
|
|
|
const eventHook = new EventHook();
|
|
|
|
system.addHook(eventHook);
|
2022-10-10 12:50:21 +00:00
|
|
|
|
|
|
|
const editor = new Editor(
|
|
|
|
serverSpace,
|
2022-11-24 11:04:00 +00:00
|
|
|
system,
|
2023-01-08 11:24:12 +00:00
|
|
|
eventHook,
|
2022-10-10 12:50:21 +00:00
|
|
|
document.getElementById("sb-root")!,
|
|
|
|
"",
|
2022-12-15 12:23:49 +00:00
|
|
|
settings,
|
2022-10-10 12:50:21 +00:00
|
|
|
);
|
|
|
|
// @ts-ignore: for convenience
|
|
|
|
window.editor = editor;
|
2022-10-25 16:50:07 +00:00
|
|
|
|
|
|
|
await editor.init();
|
2022-10-10 12:50:21 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (navigator.serviceWorker) {
|
|
|
|
navigator.serviceWorker
|
2022-11-24 11:04:00 +00:00
|
|
|
.register(new URL("/service_worker.js", location.href), {
|
2022-10-10 12:50:21 +00:00
|
|
|
type: "module",
|
|
|
|
})
|
2022-11-24 15:55:30 +00:00
|
|
|
.then(() => {
|
2022-10-10 12:50:21 +00:00
|
|
|
console.log("Service worker registered...");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log(
|
|
|
|
"No launching service worker (not present, maybe because not running on localhost or over SSL)",
|
|
|
|
);
|
|
|
|
}
|