mirror of https://github.com/espruino/BangleApps
Add saveFile function, and ensure it uses data: URI not blobs (because they don't work in Gadgetbridge)
Reduce duplication to make custom/interface use .saveFile where possible (avoiding Blob)pull/3008/head^2
parent
cc1d369f28
commit
6ff61b917e
|
@ -23,17 +23,7 @@ function saveKML(track,title) {
|
|||
</Placemark>
|
||||
</Document>
|
||||
</kml>`;
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([kml], {type: "application/vnd.google-earth.kml+xml"});
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = title+".kml";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(title+".kml", "application/vnd.google-earth.kml+xml", kml);
|
||||
}
|
||||
|
||||
function saveGPX(track, title) {
|
||||
|
@ -56,17 +46,7 @@ function saveGPX(track, title) {
|
|||
</trkseg>
|
||||
</trk>
|
||||
</gpx>`;
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([gpx], {type: "application/gpx+xml"});
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = title+".gpx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(title+".gpx", "application/gpx+xml", gpx);
|
||||
}
|
||||
|
||||
function trackLineToObject(l, hasTrackNumber) {
|
||||
|
|
|
@ -28,6 +28,10 @@ The CSV data contains the following columns:
|
|||
* PPG_o - `e.vcPPGoffs` from the `Bangle.on("HRM-raw"` event. This is the PPG offset used to map `e.vcPPG` to `e.raw` so there are no glitches when the exposure values in the sensor change.
|
||||
* BTHRM - BPM figure from external Bluetooth HRM device (this is our reference BPM)
|
||||
|
||||
## FIXME
|
||||
|
||||
The `custom.html` for the app uses the Puck.js lib directly when it should just use `customize.js` - it won't work well under Gadgetbridge and may fail on other platforms too
|
||||
|
||||
## Creator
|
||||
|
||||
[halemmerich](https://github.com/halemmerich)
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
</head>
|
||||
<body>
|
||||
<script src="../../core/lib/customize.js"></script>
|
||||
<script src="https://www.puck-js.com/puck.js"></script>
|
||||
<p>
|
||||
<div class="form-group">
|
||||
|
@ -23,20 +24,6 @@
|
|||
<p id="result"></p>
|
||||
<script>
|
||||
|
||||
function saveCSV(filename, csvData) {
|
||||
let a = document.createElement("a"),
|
||||
file = new Blob([csvData], {type: "Comma-separated value file"});
|
||||
let url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = filename+".csv";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function createCode(){
|
||||
//modes: 1 BT, 2 File
|
||||
return "var method=" + (document.getElementById("chkLocal").checked ? 2 : 1) + ";\n" + String.raw`
|
||||
|
@ -48,7 +35,7 @@ function createCode(){
|
|||
var gotBTHRM = false;
|
||||
var gotHRM = false;
|
||||
var gotAcc = false;
|
||||
|
||||
|
||||
var events = -1;
|
||||
var hrmRaw,hrmPulse,bthrmPulse
|
||||
|
||||
|
@ -59,9 +46,9 @@ function createCode(){
|
|||
let bthrmSettings = (require("Storage").readJSON("bthrm.json",1) || {});
|
||||
|
||||
Bangle.setHRMPower(1);
|
||||
|
||||
|
||||
if (bthrmSettings.replace) Bangle.origSetHRMPower(1);
|
||||
|
||||
|
||||
if (Bangle.setBTHRMPower){
|
||||
Bangle.setBTHRMPower(1);
|
||||
} else {
|
||||
|
@ -166,7 +153,7 @@ function createCode(){
|
|||
drawStatus(free>0.25*process.env.STORAGE, h++, Math.floor(free/1024) + "K");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var intervalId = -1;
|
||||
|
||||
g.setFont12x20();
|
||||
|
@ -181,7 +168,7 @@ function createCode(){
|
|||
drawStatusText("Events", h++);
|
||||
if (method == 2) drawStatusText("Storage", h++);
|
||||
updateStatus();
|
||||
|
||||
|
||||
intervalId = setInterval(()=>{
|
||||
updateStatus();
|
||||
}, 1000);
|
||||
|
@ -221,8 +208,8 @@ document.getElementById("chkLocal").addEventListener("click", function() {
|
|||
|
||||
window.addEventListener("message", function(event) {
|
||||
let msg = event.data;
|
||||
if (msg.type=="readstoragefilersp") {
|
||||
saveCSV("log.csv", msg.data);
|
||||
if (msg.type=="readstoragefilersp") {
|
||||
Util.saveCSV("log", msg.data);
|
||||
}
|
||||
}, false);
|
||||
|
||||
|
@ -240,7 +227,7 @@ document.getElementById("btnDownload").addEventListener("click", function() {
|
|||
});
|
||||
|
||||
document.getElementById("btnSave").addEventListener("click", function() {
|
||||
saveCSV("log.csv", localStorage.getItem("data"));
|
||||
Util.saveCSV("log", localStorage.getItem("data"));
|
||||
});
|
||||
|
||||
function reset(){
|
||||
|
@ -289,7 +276,7 @@ document.getElementById("btnConnect").addEventListener("click", function() {
|
|||
l.forEach(onLine);
|
||||
});
|
||||
connection.write("reset();\n", function() {
|
||||
setTimeout(function() {
|
||||
setTimeout(function() {
|
||||
connection.write("\x03\x10if(1){"+createCode()+"}\n",
|
||||
function() { console.log("Ready..."); });
|
||||
}, 1500);
|
||||
|
|
|
@ -95,17 +95,7 @@
|
|||
Util.showModal("Downloading...");
|
||||
let medicalInfoJson = getEditableContent();
|
||||
if (isJsonString(medicalInfoJson)) {
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([medicalInfoJson], { type: "application/json" });
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = medicalInfoFile;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(medicalInfoFile, "application/json", medicalInfoJson);
|
||||
} else {
|
||||
document.getElementById("info").innerHTML = errorFormat();
|
||||
}
|
||||
|
|
|
@ -96,17 +96,7 @@
|
|||
Util.showModal("Downloading...");
|
||||
let csvTimes = getEditableContent();
|
||||
if (isCorrectCsvString(csvTimes)) {
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([csvTimes], { type: "text/csv" });
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = filePresentationTimer;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(filePresentationTimer, "text/csv", csvTimes);
|
||||
} else {
|
||||
document.getElementById("info").innerHTML = errorFormat();
|
||||
}
|
||||
|
|
|
@ -75,17 +75,7 @@ ${track.map(pt=>` <gx:value>${0|pt.Skin}</gx:value>\n`).join("")}
|
|||
</Folder>
|
||||
</Document>
|
||||
</kml>`;
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([kml], {type: "application/vnd.google-earth.kml+xml"});
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = title+".kml";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(title+".kml", "application/vnd.google-earth.kml+xml", kml);
|
||||
showToast("Download finished.", "success");
|
||||
}
|
||||
|
||||
|
@ -122,17 +112,7 @@ function saveGPX(track, title) {
|
|||
</trkseg>
|
||||
</trk>
|
||||
</gpx>`;
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([gpx], {type: "application/gpx+xml"});
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = title+".gpx";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(title+".gpx", "application/gpx+xml", gpx);
|
||||
showToast("Download finished.", "success");
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ function getLapTimes() {
|
|||
});
|
||||
}
|
||||
if (task=="download") {
|
||||
Util.saveCSV(lap.n.slice(0,-5)+".csv", lap.d.map((d,n)=>[n+1,d].join(",")).join("\n"));
|
||||
Util.saveCSV(lap.n.slice(0,-5), lap.d.map((d,n)=>[n+1,d].join(",")).join("\n"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ function getData() {
|
|||
<th>Month</th>
|
||||
<th>Day</th>
|
||||
<th>Time HH:mm</th>
|
||||
<th>temperature</th>
|
||||
<th>temperature</th>
|
||||
</tr>`+data.trim().split("\n").map(l=>{
|
||||
l = l.split(";");
|
||||
return `<tr>
|
||||
|
@ -47,7 +47,7 @@ function getData() {
|
|||
|
||||
// You can call a utility function to save the data
|
||||
document.getElementById("btnSave").addEventListener("click", function() {
|
||||
Util.saveCSV("temphistory.csv", csvData);
|
||||
Util.saveCSV("temphistory", csvData);
|
||||
});
|
||||
// Or you can also delete the file
|
||||
document.getElementById("btnDelete").addEventListener("click", function() {
|
||||
|
|
|
@ -95,17 +95,7 @@
|
|||
Util.showModal("Downloading...");
|
||||
let jsonTodos = getEditableContent();
|
||||
if (isJsonString(jsonTodos)) {
|
||||
var a = document.createElement("a"),
|
||||
file = new Blob([jsonTodos], { type: "application/json" });
|
||||
var url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = fileTodoList;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function () {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
Util.saveFile(fileTodoList, "application/json", jsonTodos);
|
||||
} else {
|
||||
document.getElementById("info").innerHTML = errorFormat();
|
||||
}
|
||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
|||
Subproject commit 37a22e0c49666ec3947ad0daaf5f5675101ca485
|
||||
Subproject commit 71813fe2eaf19987cec07db850ab9d1959694f96
|
Loading…
Reference in New Issue