Load different CX scripts on mobile vs non-mobile

This commit is contained in:
Carlo Piovesan 2022-02-01 08:57:32 +01:00 committed by Alessandro Pignotti
parent 512332d439
commit 03804a1ccd

View File

@ -29,7 +29,6 @@
<link rel="stylesheet" href="/xterm/xterm.css" /> <link rel="stylesheet" href="/xterm/xterm.css" />
<script src="/xterm/xterm.js"></script> <script src="/xterm/xterm.js"></script>
<script src="/xterm/xterm-addon-fit.js"></script> <script src="/xterm/xterm-addon-fit.js"></script>
<script src="https://cheerpxdemos.leaningtech.com/publicdeploy/20220131_600/cx.js"></script>
</head> </head>
<body style="margin:0;height:100%;background:black;color:white;overflow:hidden;"> <body style="margin:0;height:100%;background:black;color:white;overflow:hidden;">
@ -184,7 +183,10 @@
} }
term.onData(readData); term.onData(readData);
structure = { //Actual CheerpX and bash specific logic
function runBash()
{
const structure = {
name: "bash", name: "bash",
cmd: "/bin/bash", cmd: "/bin/bash",
args: ["--login"], args: ["--login"],
@ -194,9 +196,6 @@
comment_line: "#", comment_line: "#",
description_line: "The original Bourne Again SHell", description_line: "The original Bourne Again SHell",
} }
//Actual CheerpX and bash specific logic
function runBash(structure)
{
if (typeof SharedArrayBuffer === "undefined") if (typeof SharedArrayBuffer === "undefined")
{ {
printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage()); printOnTerm.printError(printOnTerm.getSharedArrayBufferMissingMessage());
@ -286,9 +285,28 @@
term.registerLinkProvider(provider); term.registerLinkProvider(provider);
console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes."); console.log("Welcome. We appreciate curiosity, but be warned that keeping the DevTools open causes significant performance degradation and crashes.");
} }
initialMessage(); initialMessage();
runBash(structure);
var script = document.createElement('script');
script.type = 'text/javascript';
var cxFile = "https://cheerpxdemos.leaningtech.com/publicdeploy/";
const isMobile = navigator.userAgent.toLowerCase().match(/mobile/i);
if (isMobile)
{
printOnTerm.printMessage(["Loading mobile version...\n"]);
cxFile += '20220131_500/cx.js';
}
else
{
cxFile += '20220131_600/cx.js';
}
script.src = cxFile;
script.addEventListener("load", runBash, false);
document.head.appendChild(script);
</script> </script>
</body> </body>
</html> </html>