forked from FOSS/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)master
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`
|
||||
|
@ -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(){
|
||||
|
|
|
@ -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"));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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