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";
|
2023-07-18 21:06:13 +00:00
|
|
|
import {
|
|
|
|
maybeInitDefaultPortals,
|
|
|
|
setActivePortalMasterKey,
|
|
|
|
} from "@lumeweb/libweb";
|
2023-06-23 23:35:26 +00:00
|
|
|
import { Client } from "@lumeweb/libportal";
|
2023-07-18 21:06:13 +00:00
|
|
|
import { addContextToErr } from "@lumeweb/libkernel";
|
|
|
|
import { handleIncomingMessage } from "./message.js";
|
|
|
|
import { activeKey } from "./key.js";
|
2023-06-23 09:04:11 +00:00
|
|
|
|
2023-07-18 21:06:13 +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);
|
|
|
|
|
2023-07-18 21:06:13 +00:00
|
|
|
/*
|
|
|
|
Try to load either our saved portal(s) or the default portal(s)
|
|
|
|
*/
|
|
|
|
setActivePortalMasterKey(activeKey);
|
2023-06-23 09:04:11 +00:00
|
|
|
|
2023-07-18 21:06:13 +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
|
|
|
|
2023-07-18 21:06:13 +00:00
|
|
|
if (!portalLoadErr) {
|
|
|
|
window.addEventListener("message", handleIncomingMessage);
|
|
|
|
}
|