import "./service/metrics";
import "setimmediate";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import relativeTime from "dayjs/plugin/relativeTime";
import utc from "dayjs/plugin/utc";
import React from "react";
import ReactDOM from "react-dom";
import { BrowserRouter } from "react-router-dom";
import { RootAppRouter } from "./App";
import { QueryErrorBoundary } from "./components/error-boundaries/QueryErrorBoundary";
import { ReloadPageErrorBoundary } from "./components/error-boundaries/ReloadPageErrorBoundary";
import { ToastContextProvider } from "./components/toasts/Toasts";
import { ConfettiContextProvider } from "./contexts/ConfettiContext";
import { setupQueryClientProvider } from "./data/setup";
import "./index.css";
import { PaymentContextProvider } from "./payment-context";
import { ThemeContextProvider } from "./theme-context";
import { UserContextProvider } from "./user-context";
import { getURLHash, isWebsiteSlug } from "./utils";
import minimalLoginHtml from "./minimal-login.html";
const MINIMAL_MODE_OVERRIDE_KEY = "minimal_gitpod_io_mode";
function isAppRoute(pathname: string): boolean {
const appRoutes = [
"/workspaces",
"/new",
"/start",
"/settings",
"/billing",
"/members",
"/sso",
"/orgs",
"/repositories",
"/prebuilds",
"/admin",
"/login",
"/oauth-approval",
"/blocked",
"/from-referrer",
"/usage",
"/insights",
"/org-admin",
"/quickstart",
"/account",
"/integrations",
"/notifications",
"/preferences",
"/variables",
"/tokens",
"/keys",
"/open",
"/sorry",
"/t/",
"/projects/",
"/user/",
"/access-control",
"/old-team-plans",
"/teams",
"/subscription",
"/upgrade-subscription",
"/plans",
];
return appRoutes.some((route) => pathname === route || pathname.startsWith(route + "/"));
}
function handleMinimalGitpodIoMode(): void {
const pathname = window.location.pathname;
const search = window.location.search;
const hash = window.location.hash;
const hashContent = hash.replace(/^#\/?/, "");
if (isWebsiteSlug(pathname)) {
window.location.href = `https://www.gitpod.io${pathname}${search}`;
return;
}
if (hashContent !== "") {
let normalizedHash = hash;
if (/^#\/?((https:\/\/)?github\.dev\/)/i.test(hash)) {
normalizedHash = hash.replace(/github\.dev\//gi, "github.com/");
}
window.location.href = `https://app.ona.com/${normalizedHash}`;
return;
}
if (/^\/(github|gitlab|bitbucket)\.(com|org)\//.test(pathname)) {
window.location.href = `https://app.ona.com/#${pathname.slice(1)}${search}`;
return;
}
if (isAppRoute(pathname)) {
renderMinimalLoginPage();
return;
}
if (pathname === "/" || pathname === "") {
renderMinimalLoginPage();
return;
}
window.location.href = `https://www.gitpod.io${pathname}${search}`;
}
function extractBodyContent(html: string): string {
const parser = new DOMParser();
const doc = parser.parseFromString(html, "text/html");
return doc.body.innerHTML;
}
function renderMinimalLoginPage(): void {
const bodyContent = extractBodyContent(minimalLoginHtml);
const root = document.getElementById("root");
if (root) {
root.innerHTML = bodyContent;
} else {
document.body.innerHTML = bodyContent;
}
}
function bootFullApp(): void {
const hash = getURLHash();
if (/^(https:\/\/)?github\.dev\//i.test(hash)) {
window.location.hash = hash.replace(/^(https:\/\/)?github\.dev\//i, "https://github.com/");
} else if (/^([^/]+?=[^/]*?|prebuild)\/(https:\/\/)?github\.dev\//i.test(hash)) {
window.location.hash = hash.replace(
/^([^/]+?=[^/]*?|prebuild)\/(https:\/\/)?github\.dev\//i,
"$1/https://github.com/",
);
}
const GitpodQueryClientProvider = setupQueryClientProvider();
dayjs.extend(relativeTime);
dayjs.extend(utc);
dayjs.extend(duration);
ReactDOM.render(
<React.StrictMode>
<ThemeContextProvider>
<ReloadPageErrorBoundary>
<BrowserRouter>
<GitpodQueryClientProvider>
{}
<QueryErrorBoundary>
<ConfettiContextProvider>
<ToastContextProvider>
<UserContextProvider>
<PaymentContextProvider>
<RootAppRouter />
</PaymentContextProvider>
</UserContextProvider>
</ToastContextProvider>
</ConfettiContextProvider>
</QueryErrorBoundary>
</GitpodQueryClientProvider>
</BrowserRouter>
</ReloadPageErrorBoundary>
</ThemeContextProvider>
</React.StrictMode>,
document.getElementById("root"),
);
}
function isExactGitpodIo(): boolean {
return window.location.hostname === "gitpod.io";
}
const bootApp = () => {
let minimalMode = false;
if (isExactGitpodIo()) {
const pathname = window.location.pathname;
if (isWebsiteSlug(pathname)) {
window.location.href = `https://www.gitpod.io${pathname}${window.location.search}`;
return;
}
minimalMode = true;
}
try {
if (localStorage.getItem(MINIMAL_MODE_OVERRIDE_KEY) === "true") {
minimalMode = true;
}
} catch {
}
if (minimalMode) {
handleMinimalGitpodIoMode();
return;
}
bootFullApp();
};
bootApp();