kernel/src/index.ts

40 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-06-23 09:04:11 +00:00
import { logLargeObjects } from "./logLargeState.js";
import { log, logErr } from "./log.js";
import { KERNEL_DISTRO, KERNEL_VERSION } from "./version.js";
import {
maybeInitDefaultPortals,
setActivePortalMasterKey,
} from "@lumeweb/libweb";
import { Client } from "@lumeweb/libportal";
import { addContextToErr } from "@lumeweb/libkernel";
import { handleIncomingMessage } from "./message.js";
import { activeKey } from "./key.js";
2023-06-23 09:04:11 +00:00
declare global {
interface Window {
bootloaderPortals: Client[];
}
}
2023-06-23 09:04:11 +00:00
// Kick off the thread that will periodically log all of the large objects in
// the kernel, so that it's easier to check for memory leaks.
logLargeObjects();
// Write a log that declares the kernel version and distribution.
log("init", "Lume Web Kernel v" + KERNEL_VERSION + "-" + KERNEL_DISTRO);
/*
Try to load either our saved portal(s) or the default portal(s)
*/
setActivePortalMasterKey(activeKey);
2023-06-23 09:04:11 +00:00
let [, portalLoadErr] = maybeInitDefaultPortals();
if (portalLoadErr) {
let err = addContextToErr(portalLoadErr, "unable to init portals");
logErr(err);
}
2023-06-23 09:04:11 +00:00
if (!portalLoadErr) {
window.addEventListener("message", handleIncomingMessage);
}