silverbullet/web/boot.ts

43 lines
1.2 KiB
TypeScript
Raw Normal View History

import { safeRun } from "../common/util.ts";
2023-07-14 22:56:20 +08:00
import { Client } from "./client.ts";
2023-08-26 14:31:51 +08:00
const thinClientMode = window.silverBulletConfig.thinClientMode === "on";
safeRun(async () => {
2023-07-14 22:56:20 +08:00
console.log("Booting SilverBullet...");
2023-07-14 22:56:20 +08:00
const client = new Client(
document.getElementById("sb-root")!,
2023-08-26 14:31:51 +08:00
thinClientMode,
);
2023-07-14 22:56:20 +08:00
await client.init();
window.client = client;
});
if (navigator.serviceWorker) {
navigator.serviceWorker
2022-11-24 19:04:00 +08:00
.register(new URL("/service_worker.js", location.href), {
type: "module",
})
2022-11-24 23:55:30 +08:00
.then(() => {
console.log("Service worker registered...");
});
2023-08-26 14:31:51 +08:00
if (!thinClientMode) {
navigator.serviceWorker.ready.then((registration) => {
registration.active!.postMessage({
type: "config",
config: window.silverBulletConfig,
});
});
2023-08-26 14:31:51 +08:00
}
} else {
console.warn(
"Not launching service worker, likely because not running from localhost or over HTTPs. This means SilverBullet will not be available offline.",
);
}
2023-05-24 11:42:24 +08:00
if (!globalThis.indexedDB) {
alert(
"SilverBullet requires IndexedDB to operate and it is not available in your browser. Please use a recent version of Chrome, Firefox (not in private mode) or Safari.",
);
}