Files
crowd-funder-for-time-pwa/src/main.web.ts
T
trentlarson b721486012 adjust a few more Time Safari names to Giftopia (but still many TimeSafari refs exist)
... and previous commit was actually for optimization as Google will soon require
2026-11-01 16:52:33 -07:00

58 lines
2.2 KiB
TypeScript

import { logger } from "./utils/logger";
import { registerWebShareTargetWorker } from "./libs/webShareTarget";
const platform = process.env.VITE_PLATFORM;
/**
* Browsers withhold crypto.subtle outside secure contexts (HTTPS, localhost,
* 127.0.0.1, [::1]), and identity creation cannot run without it. Addresses
* like http://[::]:8000 or http://192.168.x.x would otherwise fail later with
* a misleading "could not open its data" startup error. main.common is loaded
* only after this check because importing the router starts navigation.
*/
function showInsecureContextError(): void {
const container = document.getElementById("app");
if (!container) {
return;
}
container.innerHTML = `
<section style="max-width: 40rem; margin: 3rem auto; padding: 0 1rem; font-family: sans-serif; line-height: 1.5;">
<h1 style="font-size: 1.25rem; font-weight: 600;">TimeSafari Cannot Start Here</h1>
<p>This page must be opened over HTTPS or from <code>localhost</code>.</p>
<p>The browser does not treat <code></code> as secure, so it disables the cryptography the app uses for identities.</p>
<p>On a local server, use <code>http://localhost:PORT/</code> instead of <code>http://[::]:PORT/</code> or <code>http://0.0.0.0:PORT/</code>.</p>
</section>`;
const originCode = container.querySelectorAll("code")[1];
if (originCode) {
originCode.textContent = window.location.origin;
}
}
if (!window.isSecureContext) {
logger.error("[Web] Not a secure context; app will not start", {
origin: window.location.origin,
});
showInsecureContextError();
} else {
import("./main.common").then(({ initializeApp }) => {
const app = initializeApp();
// Note: Worker initialization is now handled by WebPlatformService
// This ensures single-point database access and prevents double migrations
if (platform === "web" || platform === "development") {
logger.debug(
"[Web] Database initialization will be handled by WebPlatformService",
);
} else {
logger.debug("[Web] SQL not initialized for platform", { platform });
}
app.mount("#app");
// Handles the manifest's share_target POST (see public/sw.js)
if (platform === "web") {
registerWebShareTargetWorker();
}
});
}