UNPKG

@cocalc/static

Version:

CoCalc's static frontend Webpack-based build system and framework

105 lines 4.53 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const jsx_runtime_1 = require("react/jsx-runtime"); /* * This file is part of CoCalc: Copyright © 2020 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ /* ES6 support https://www.w3schools.com/js/js_versions.asp Firefox: 54 Edge: 14 Safari: 10 Opera: 55 Chrome is wrong on that page, I assume we should check for 61 or 62. */ const react_1 = require("react"); const APP_NAME = "CoCalc"; const link_1 = __importDefault(require("./link")); /* credits: https://stackoverflow.com/a/38080051/54236 */ function getSpec() { const mstr = /(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i; const ua = navigator.userAgent; let tem; let M = ua.match(mstr) || []; if (/trident/i.test(M[1])) { tem = /\brv[ :]+(\d+)/g.exec(ua) || []; return { name: "IE", version: parseInt(tem[1]) || NaN, buildID: "" }; } if (M[1] === "Chrome") { tem = ua.match(/\b(OPR|Edge)\/(\d+)/); if (tem != null) return { name: tem[1].replace("OPR", "Opera"), version: parseInt(tem[2]), buildID: "", }; } M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, "-?"]; if ((tem = ua.match(/version\/(\d+)/i)) != null) { M.splice(1, 1, tem[1]); } let buildID = navigator.buildID; // only exists for FF, this below is for Chrome if (buildID == null && navigator.appVersion != null) { try { const vers = navigator.appVersion.match(/\bChrome\/([0-9.]+)\b/); if (vers != null) { buildID = vers[1].split(".").map((x) => parseInt(x)); } } catch { console.log(`Unable to extract buildID from ${navigator.appVersion}`); } } return { name: M[0], version: parseInt(M[1]), buildID, }; } const SKIP_TOKEN = "skip_preflight"; const STYLE = { textAlign: "center", border: "1px solid #ccc", borderRadius: "5px", margin: "30px", padding: "30px", backgroundColor: "#f8f8f8", fontFamily: "sans-serif", }; function allowedToRun() { if (window.location.href.includes(SKIP_TOKEN)) { return true; } try { // Just test for optional chaining -- it's a pretty good proxy for having // a modern browser. See https://caniuse.com/?search=%3F. eval("window?.foo"); } catch (_err) { return false; } return true; } function PreflightCheck() { const allowed = allowedToRun(); (0, react_1.useLayoutEffect)(() => { if (!allowed) { // Cause everything to stop right after // the initial render. window.stop(); } }, [allowed]); if (allowed) { console.log("Browser is supported."); return null; } const spec = getSpec(); return ((0, jsx_runtime_1.jsxs)("div", { style: STYLE, children: [(0, jsx_runtime_1.jsx)("h1", { style: { color: "red", fontSize: "400%" }, children: "\u26A0" }), (0, jsx_runtime_1.jsxs)("h2", { children: [APP_NAME, " does not support ", spec.name, " version ", spec.version, "."] }), (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsxs)("p", { children: ["We recommend that you use the newest version of", " ", (0, jsx_runtime_1.jsx)(link_1.default, { href: "https://google.com/chrome", children: "Google Chrome" }), ",", " ", (0, jsx_runtime_1.jsx)(link_1.default, { href: "https://www.mozilla.org/", children: "Firefox" }), ", or", " ", (0, jsx_runtime_1.jsx)(link_1.default, { href: "https://support.apple.com/downloads/safari", children: "Safari" }), "."] }) }), (0, jsx_runtime_1.jsxs)("div", { style: { marginTop: "20px" }, children: ["Learn more about our", " ", (0, jsx_runtime_1.jsx)(link_1.default, { href: "https://github.com/sagemathinc/cocalc/wiki/BrowserRequirements", children: "browser requirements" }), "."] }), (0, jsx_runtime_1.jsx)("div", { style: { marginTop: "20px", fontWeight: "bold", fontSize: "115%" }, children: (0, jsx_runtime_1.jsxs)("a", { href: `./app?${SKIP_TOKEN}`, style: { textDecoration: "none" }, children: ["Use ", APP_NAME, " with my unsupported browser anyways..."] }) })] })); } exports.default = PreflightCheck; //# sourceMappingURL=preflight-checks.js.map