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>
|
</Placemark>
|
||||||
</Document>
|
</Document>
|
||||||
</kml>`;
|
</kml>`;
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(title+".kml", "application/vnd.google-earth.kml+xml", kml);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveGPX(track, title) {
|
function saveGPX(track, title) {
|
||||||
|
@ -56,17 +46,7 @@ function saveGPX(track, title) {
|
||||||
</trkseg>
|
</trkseg>
|
||||||
</trk>
|
</trk>
|
||||||
</gpx>`;
|
</gpx>`;
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(title+".gpx", "application/gpx+xml", gpx);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function trackLineToObject(l, hasTrackNumber) {
|
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.
|
* 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)
|
* 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
|
## Creator
|
||||||
|
|
||||||
[halemmerich](https://github.com/halemmerich)
|
[halemmerich](https://github.com/halemmerich)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<script src="../../core/lib/customize.js"></script>
|
||||||
<script src="https://www.puck-js.com/puck.js"></script>
|
<script src="https://www.puck-js.com/puck.js"></script>
|
||||||
<p>
|
<p>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
@ -23,20 +24,6 @@
|
||||||
<p id="result"></p>
|
<p id="result"></p>
|
||||||
<script>
|
<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(){
|
function createCode(){
|
||||||
//modes: 1 BT, 2 File
|
//modes: 1 BT, 2 File
|
||||||
return "var method=" + (document.getElementById("chkLocal").checked ? 2 : 1) + ";\n" + String.raw`
|
return "var method=" + (document.getElementById("chkLocal").checked ? 2 : 1) + ";\n" + String.raw`
|
||||||
|
@ -48,7 +35,7 @@ function createCode(){
|
||||||
var gotBTHRM = false;
|
var gotBTHRM = false;
|
||||||
var gotHRM = false;
|
var gotHRM = false;
|
||||||
var gotAcc = false;
|
var gotAcc = false;
|
||||||
|
|
||||||
var events = -1;
|
var events = -1;
|
||||||
var hrmRaw,hrmPulse,bthrmPulse
|
var hrmRaw,hrmPulse,bthrmPulse
|
||||||
|
|
||||||
|
@ -59,9 +46,9 @@ function createCode(){
|
||||||
let bthrmSettings = (require("Storage").readJSON("bthrm.json",1) || {});
|
let bthrmSettings = (require("Storage").readJSON("bthrm.json",1) || {});
|
||||||
|
|
||||||
Bangle.setHRMPower(1);
|
Bangle.setHRMPower(1);
|
||||||
|
|
||||||
if (bthrmSettings.replace) Bangle.origSetHRMPower(1);
|
if (bthrmSettings.replace) Bangle.origSetHRMPower(1);
|
||||||
|
|
||||||
if (Bangle.setBTHRMPower){
|
if (Bangle.setBTHRMPower){
|
||||||
Bangle.setBTHRMPower(1);
|
Bangle.setBTHRMPower(1);
|
||||||
} else {
|
} else {
|
||||||
|
@ -166,7 +153,7 @@ function createCode(){
|
||||||
drawStatus(free>0.25*process.env.STORAGE, h++, Math.floor(free/1024) + "K");
|
drawStatus(free>0.25*process.env.STORAGE, h++, Math.floor(free/1024) + "K");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var intervalId = -1;
|
var intervalId = -1;
|
||||||
|
|
||||||
g.setFont12x20();
|
g.setFont12x20();
|
||||||
|
@ -181,7 +168,7 @@ function createCode(){
|
||||||
drawStatusText("Events", h++);
|
drawStatusText("Events", h++);
|
||||||
if (method == 2) drawStatusText("Storage", h++);
|
if (method == 2) drawStatusText("Storage", h++);
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
intervalId = setInterval(()=>{
|
intervalId = setInterval(()=>{
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
@ -221,8 +208,8 @@ document.getElementById("chkLocal").addEventListener("click", function() {
|
||||||
|
|
||||||
window.addEventListener("message", function(event) {
|
window.addEventListener("message", function(event) {
|
||||||
let msg = event.data;
|
let msg = event.data;
|
||||||
if (msg.type=="readstoragefilersp") {
|
if (msg.type=="readstoragefilersp") {
|
||||||
saveCSV("log.csv", msg.data);
|
Util.saveCSV("log", msg.data);
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
@ -240,7 +227,7 @@ document.getElementById("btnDownload").addEventListener("click", function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById("btnSave").addEventListener("click", function() {
|
document.getElementById("btnSave").addEventListener("click", function() {
|
||||||
saveCSV("log.csv", localStorage.getItem("data"));
|
Util.saveCSV("log", localStorage.getItem("data"));
|
||||||
});
|
});
|
||||||
|
|
||||||
function reset(){
|
function reset(){
|
||||||
|
@ -289,7 +276,7 @@ document.getElementById("btnConnect").addEventListener("click", function() {
|
||||||
l.forEach(onLine);
|
l.forEach(onLine);
|
||||||
});
|
});
|
||||||
connection.write("reset();\n", function() {
|
connection.write("reset();\n", function() {
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
connection.write("\x03\x10if(1){"+createCode()+"}\n",
|
connection.write("\x03\x10if(1){"+createCode()+"}\n",
|
||||||
function() { console.log("Ready..."); });
|
function() { console.log("Ready..."); });
|
||||||
}, 1500);
|
}, 1500);
|
||||||
|
|
|
@ -95,17 +95,7 @@
|
||||||
Util.showModal("Downloading...");
|
Util.showModal("Downloading...");
|
||||||
let medicalInfoJson = getEditableContent();
|
let medicalInfoJson = getEditableContent();
|
||||||
if (isJsonString(medicalInfoJson)) {
|
if (isJsonString(medicalInfoJson)) {
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(medicalInfoFile, "application/json", medicalInfoJson);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("info").innerHTML = errorFormat();
|
document.getElementById("info").innerHTML = errorFormat();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,17 +96,7 @@
|
||||||
Util.showModal("Downloading...");
|
Util.showModal("Downloading...");
|
||||||
let csvTimes = getEditableContent();
|
let csvTimes = getEditableContent();
|
||||||
if (isCorrectCsvString(csvTimes)) {
|
if (isCorrectCsvString(csvTimes)) {
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(filePresentationTimer, "text/csv", csvTimes);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("info").innerHTML = errorFormat();
|
document.getElementById("info").innerHTML = errorFormat();
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,17 +75,7 @@ ${track.map(pt=>` <gx:value>${0|pt.Skin}</gx:value>\n`).join("")}
|
||||||
</Folder>
|
</Folder>
|
||||||
</Document>
|
</Document>
|
||||||
</kml>`;
|
</kml>`;
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(title+".kml", "application/vnd.google-earth.kml+xml", kml);
|
||||||
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);
|
|
||||||
showToast("Download finished.", "success");
|
showToast("Download finished.", "success");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,17 +112,7 @@ function saveGPX(track, title) {
|
||||||
</trkseg>
|
</trkseg>
|
||||||
</trk>
|
</trk>
|
||||||
</gpx>`;
|
</gpx>`;
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(title+".gpx", "application/gpx+xml", gpx);
|
||||||
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);
|
|
||||||
showToast("Download finished.", "success");
|
showToast("Download finished.", "success");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,7 @@ function getLapTimes() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (task=="download") {
|
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>Month</th>
|
||||||
<th>Day</th>
|
<th>Day</th>
|
||||||
<th>Time HH:mm</th>
|
<th>Time HH:mm</th>
|
||||||
<th>temperature</th>
|
<th>temperature</th>
|
||||||
</tr>`+data.trim().split("\n").map(l=>{
|
</tr>`+data.trim().split("\n").map(l=>{
|
||||||
l = l.split(";");
|
l = l.split(";");
|
||||||
return `<tr>
|
return `<tr>
|
||||||
|
@ -47,7 +47,7 @@ function getData() {
|
||||||
|
|
||||||
// You can call a utility function to save the data
|
// You can call a utility function to save the data
|
||||||
document.getElementById("btnSave").addEventListener("click", function() {
|
document.getElementById("btnSave").addEventListener("click", function() {
|
||||||
Util.saveCSV("temphistory.csv", csvData);
|
Util.saveCSV("temphistory", csvData);
|
||||||
});
|
});
|
||||||
// Or you can also delete the file
|
// Or you can also delete the file
|
||||||
document.getElementById("btnDelete").addEventListener("click", function() {
|
document.getElementById("btnDelete").addEventListener("click", function() {
|
||||||
|
|
|
@ -95,17 +95,7 @@
|
||||||
Util.showModal("Downloading...");
|
Util.showModal("Downloading...");
|
||||||
let jsonTodos = getEditableContent();
|
let jsonTodos = getEditableContent();
|
||||||
if (isJsonString(jsonTodos)) {
|
if (isJsonString(jsonTodos)) {
|
||||||
var a = document.createElement("a"),
|
Util.saveFile(fileTodoList, "application/json", jsonTodos);
|
||||||
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);
|
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("info").innerHTML = errorFormat();
|
document.getElementById("info").innerHTML = errorFormat();
|
||||||
}
|
}
|
||||||
|
|
2
core
2
core
|
@ -1 +1 @@
|
||||||
Subproject commit 37a22e0c49666ec3947ad0daaf5f5675101ca485
|
Subproject commit 71813fe2eaf19987cec07db850ab9d1959694f96
|
Loading…
Reference in New Issue