Skip to content

Commit 0bb34a5

Browse files
author
Jean-Baptiste Doderlein
committed
Add micropython interpreter and test GH PAges with webworkers
1 parent dfeaac6 commit 0bb34a5

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

src/index.html

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
content="An efficient, intuitive and cross-platform web IDE for the Python language (recent: v3.7), with your code interpreted and running in your browser! (no server is needed!)">
77
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
88
<meta name="viewport" content="width=device-width, initial-scale=1.0">
9+
<script src="./mini-coi.js" scope="./"></script>
910
<link rel="manifest" href="manifest.json">
1011
<link rel="apple-touch-icon" sizes="57x57" href="icon/apple-icon-57x57.png">
1112
<link rel="apple-touch-icon" sizes="60x60" href="icon/apple-icon-60x60.png">
@@ -106,7 +107,7 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
106107
<!-- Clean console button -->
107108
<div class="fixed-action-btn hide-on-small-and-down" style="bottom: 15px; right: 15px;">
108109
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
109-
onclick="toplevelcallback.clear()"><i
110+
onclick="terminal.terminal.clear()"><i
110111
class="material-icons">delete</i></a>
111112
</div>
112113

@@ -115,7 +116,7 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
115116
<a class="btn-floating btn-small waves-effect waves-light zoom-button" onclick="exec_all(editors[current_editor()])"><i
116117
class="material-icons">play_arrow</i></a>
117118
<a class="btn-floating btn-small waves-effect waves-light zoom-button"
118-
onclick="toplevelcallback.clear()"><i
119+
onclick="terminal.terminal.clear()"><i
119120
class="material-icons">delete</i></a>
120121
</div>
121122

@@ -174,7 +175,7 @@ <h4>Configuration</h4>
174175
class="material-icons">remove</i></a>
175176
</div>
176177

177-
<a class="waves-effect waves-light btn config-element" onclick="toplevelcallback.reset()"><i
178+
<a class="waves-effect waves-light btn config-element" onclick="terminal.terminal.clear()"><i
178179
class="material-icons right">refresh</i>Reset
179180
OCaml Interpreter</a>
180181
</div>
@@ -289,9 +290,13 @@ <h4>Graphics main window</h4>
289290
<div id="box_2" class="box console-box">
290291
<div id="emtopx" style="font-size: var(--toplevel-font-size);display: none;"></div>
291292
<div id="toplevel-container">
292-
<script id="toplevel-terminal" type="mpy" terminal>
293+
<mpy-config>
294+
interpreter = "js/micropython/micropython.mjs"
295+
</mpy-config>
296+
<script id="toplevel-terminal" type="mpy" terminal worker>
293297
import code
294298
from pyscript import window
299+
295300
window.change_font_size("toplevel",0)
296301
code.interact()
297302
</script>
@@ -416,6 +421,7 @@ <h4>Graphics main window</h4>
416421
(for_statement)@bloc
417422
(while_statement)@bloc
418423
(try_statement)@bloc
424+
(import_statement)@expr
419425
(expression_statement)@expr`);
420426
});
421427
});

src/js/micropython/micropython.mjs

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

src/js/micropython/micropython.wasm

381 KB
Binary file not shown.

src/mini-coi.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*! coi-serviceworker v0.1.7 - Guido Zuidhof and contributors, licensed under MIT */
2+
/*! mini-coi - Andrea Giammarchi and contributors, licensed under MIT */
3+
(({ document: d, navigator: { serviceWorker: s } }) => {
4+
if (d) {
5+
const { currentScript: c } = d;
6+
s.register(c.src, { scope: c.getAttribute('scope') || '.' }).then(r => {
7+
r.addEventListener('updatefound', () => location.reload());
8+
if (r.active && !s.controller) location.reload();
9+
});
10+
}
11+
else {
12+
addEventListener('install', () => skipWaiting());
13+
addEventListener('activate', e => e.waitUntil(clients.claim()));
14+
addEventListener('fetch', e => {
15+
const { request: r } = e;
16+
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
17+
e.respondWith(fetch(r).then(r => {
18+
const { body, status, statusText } = r;
19+
if (!status || status > 399) return r;
20+
const h = new Headers(r.headers);
21+
h.set('Cross-Origin-Opener-Policy', 'same-origin');
22+
h.set('Cross-Origin-Embedder-Policy', 'require-corp');
23+
h.set('Cross-Origin-Resource-Policy', 'cross-origin');
24+
return new Response(body, { status, statusText, headers: h });
25+
}));
26+
});
27+
}
28+
})(self);
29+

0 commit comments

Comments
 (0)