Skip to content

Commit be75bad

Browse files
author
Jean-Baptiste Doderlein
committed
Minor fix + update service worker to cache
1 parent 7146499 commit be75bad

File tree

4 files changed

+21
-127
lines changed

4 files changed

+21
-127
lines changed

src/index.html

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
6363
</ul>
6464
<ul id="menu-button" class="right">
6565
<li id="flexible-mobile-button">
66-
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.ml', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));"><i
66+
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.py', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));"><i
6767
class="material-icons">add</i></a></li>
6868
<li><a onclick="exec_all(editors[current_editor()])"><i class="material-icons">play_arrow</i></a></li>
6969
<li><a onclick="save(editors[current_editor()]);"><i class="material-icons">save</i></a></li>
@@ -83,7 +83,7 @@ <h2 class="center white-text">Loading Python Interpreter</h2>
8383
<!-- Mobile Sidenav -->
8484
<ul id="mobile-sidenav" class="sidenav mobile-tabs tabs">
8585
<li id="add_tab" class="tab col s3 onglet">
86-
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.ml', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));">
86+
<a onclick="editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.py', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));">
8787
Add file
8888
<i class="material-icons add-icon">add</i>
8989
</a>
@@ -232,7 +232,7 @@ <h5>Search / Replace</h5>
232232
<div class="modal-content">
233233
<h4>Save as ...</h4>
234234
<div class="input-field col s6">
235-
<input placeholder="untitled.ml" id="saveas_text" type="text" class="white-text">
235+
<input placeholder="untitled.py" id="saveas_text" type="text" class="white-text">
236236
</div>
237237
</div>
238238
<div class="modal-footer help">
@@ -270,9 +270,6 @@ <h4>Graphics main window</h4>
270270
<div id="toplevel-container">
271271
<mpy-config>
272272
interpreter = "js/micropython/micropython.mjs"
273-
[js_modules.main]
274-
"https://cdn.jsdelivr.net/npm/@xterm/addon-web-links/+esm" = "weblinks"
275-
"https://cdn.jsdelivr.net/npm/@xterm/addon-fit@0.10.0/+esm" = "fit"
276273
</mpy-config>
277274
<script id="toplevel-terminal" type="mpy" terminal worker name="toplevel">
278275
import code

src/js/editor_change.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ let calculate_highlight = function (instance) {
155155
* @return {void} Nothing
156156
*/
157157
function save(instance) {
158-
if (instance.name == "untitled.ml") {
158+
if (instance.name == "untitled.py") {
159159
M.Modal.getInstance(document.getElementById('saveas')).open()
160160
} else {
161161
program_save(instance);
@@ -169,12 +169,12 @@ function save(instance) {
169169
*/
170170
function name_and_save(instance) {
171171
let potential_filename = document.getElementById('saveas_text').value;
172-
let fileNameToSaveAs = "untitled.ml";
172+
let fileNameToSaveAs = "untitled.py";
173173
if (potential_filename !== "") {
174-
if (potential_filename.substr(-3, 3) == ".ml") {
174+
if (potential_filename.substr(-3, 3) == ".py") {
175175
fileNameToSaveAs = potential_filename
176176
} else {
177-
fileNameToSaveAs = potential_filename + ".ml"
177+
fileNameToSaveAs = potential_filename + ".py"
178178
}
179179
}
180180
instance.name = fileNameToSaveAs;
@@ -593,7 +593,7 @@ function navbar_resize() {
593593
let mobile_button = document.getElementById("flexible-mobile-button");
594594
mobile_button.children[0].children[0].innerText = "add";
595595
mobile_button.children[0].removeAttribute("href");
596-
mobile_button.children[0].setAttribute("onclick", "editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.ml', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));");
596+
mobile_button.children[0].setAttribute("onclick", "editors[Math.max(...Object.keys(editors).map(x => +x))+1] = create_editor(id = Math.max(...Object.keys(editors).map(x => +x))+1, name = 'untitled.py', theme= editors[Math.min(...Object.keys(editors).map(x => +x))].getOption('theme'));");
597597
mobile_button.children[0].removeAttribute("data-target");
598598
mobile_button.children[0].removeAttribute("class");
599599
// transfer tabs to navbar

src/mini-coi.js

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const staticAssets = [
55
// './',
66
'./manifest.json',
77
'./index.html',
8-
'./favicon.ico'
98
];
109

1110

@@ -19,25 +18,23 @@ const staticAssets = [
1918
}
2019
else {
2120
addEventListener('install', async event => {
22-
skipWaiting();
2321
const cache = await caches.open('static-cache');
2422
cache.addAll(staticAssets);
23+
skipWaiting();
2524
});
2625
addEventListener('activate', e => e.waitUntil(clients.claim()));
27-
addEventListener('fetch', e => {
28-
const req = e.request;
29-
const url = new URL(req.url);
26+
addEventListener('fetch', async e => {
3027
const { request: r } = e;
28+
const url = new URL(r.url);
3129
let cached_req;
32-
/*
3330
if(url.origin === location.url){
34-
cached_req = cacheFirst(req);
35-
} else {
36-
cached_req = newtorkFirst(req);
31+
cached_req = caches.match(r) || fetch(r);
32+
}
33+
else {
34+
cached_req = newtorkFirst(r);
3735
}
38-
*/
3936
if (r.cache === 'only-if-cached' && r.mode !== 'same-origin') return;
40-
e.respondWith(fetch(r).then(r => {
37+
e.respondWith(cached_req.then(r => {
4138
const { body, status, statusText } = r;
4239
if (!status || status > 399) return r;
4340
const h = new Headers(r.headers);
@@ -50,20 +47,10 @@ const staticAssets = [
5047
}
5148
})(self);
5249

53-
async function cacheFirst(req){
54-
const cachedResponse = caches.match(req);
55-
return cachedResponse || fetch(req);
56-
}
57-
58-
async function newtorkFirst(req){
59-
const cache = await caches.open('dynamic-cache');
60-
61-
try {
62-
const res = await fetch(req);
63-
cache.put(req, res.clone());
64-
return res;
65-
} catch (error) {
66-
return await cache.match(req);
67-
}
50+
async function newtorkFirst(r){
51+
const cache = await caches.open('dynamic-cache');
52+
const res = await fetch(r);
53+
cache.put(r, res.clone());
54+
return res;
6855
}
6956

src/serviceWorker.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)