Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proof of concept cloud-compiled share page #1274

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 148 additions & 0 deletions docfiles/leanscript.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">

<head>
<meta charset="UTF-8">
<title>@name@</title>

<!-- @include meta.html -->

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport"
content="width=device-width,height=device-height,user-scalable=no,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0">

<link rel="stylesheet" href="./static/script-page.css" />

<link rel="alternate" type="application/json+oembed" href="@oembedurl@&format=json" />
<link rel="alternate" type="text/xml+oembed" href="@oembedurl@&format=xml" />

<style>
/* fix for iOS; see https://github.com/PierBover/ios-iframe-fix */
#wrap {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
overflow-y: hidden;
-webkit-overflow-scrolling: touch;
}

html {
width: 100%;
height: 100%;
overflow: hidden;
}

body {
height: 100%;
}

#wrap iframe {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
}
</style>
<style id="injected-style">
</style>
</head>

<body id='root' class='root expandIt share-page'>

<!-- @include macros.html -->

<div class="ui main container mainbody script-content">
<div id="wrap">
<div class="simframe ui embed">
<iframe id="simframe" title="Simulator" allowfullscreen="" allow="autoplay"
sandbox="allow-same-origin allow-scripts" class="no-select" src="/sim/simulator.html"
frameborder="0">
</iframe>
</div>
</div>

<script type="text/javascript">
(function () {
var code = "";
var isReady = false;
var simState = {}
var simStateChanged = false

function fetchCode() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (xhttp.readyState == 4 && xhttp.status == 200) {
code = xhttp.responseText;
startSim();
}
};
xhttp.open("GET", "/api/@id@/js?v=@simversion@", true);
xhttp.send();
}

function startSim() {
if (!code || !isReady)
return
const runMsg = {
type: "run",
parts: [],
"code": code,
partDefinitions: {},
cdnUrl: "/cdn/",
version: "lean:@id@",
storedState: simState,
frameCounter: 1,
options: {
"theme": "green",
"player": ""
},
"id": "green-" + Math.random()
}
const frame = document.getElementById("simframe");
frame.contentWindow.postMessage(runMsg, "*");
}

fetchCode()

try {
simState = JSON.parse(localStorage["sim-@id@"])
} catch (e) {
simState = {}
}
setInterval(function () {
if (simStateChanged)
localStorage["sim-@id@"] = JSON.stringify(simState)
simStateChanged = false
}, 200)

window.addEventListener('message', function (ev) {
var d = ev.data
if (d.type == "ready") {
isReady = true;
startSim();
} else if (d.type == "simulator") {
switch (d.command) {
case "restart":
startSim();
break;
case "setstate":
simState[d.stateKey] = d.stateValue
simStateChanged = true
break;
}
} else {
console.log(d)
}
}, false);
})()
</script>

</div>

<!-- @include tracking.html -->
</body>

</html>
3 changes: 2 additions & 1 deletion pxtarget.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,8 @@
"autoRunLight": false,
"emptyRunCode": "pxsim.pxtcore.updateScreen(new pxsim.RefImage(160, 120, 4))",
"aspectRatio": 0.85,
"dynamicBoardDefinition": true
"dynamicBoardDefinition": true,
"leanShare": true
},
"appTheme": {
"logoUrl": "https://github.com/Microsoft/pxt-arcade",
Expand Down