mirror of https://github.com/espruino/BangleApps
messagesdebug: new app, log all `message` events to storage file
parent
1f1b8a20d5
commit
0dc07fb418
|
@ -0,0 +1 @@
|
|||
0.01: New app!
|
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,3 @@
|
|||
Bangle.on("message", (t, m) => {
|
||||
require("Storage").open("messagesdebug.log", "a").write(`${t}: ${JSON.stringify(m)}\n`);
|
||||
});
|
|
@ -0,0 +1,71 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<link rel="stylesheet" href="../../css/spectre.min.css">
|
||||
<title>Messages Debug</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="data"></div>
|
||||
<button class="btn btn-default" id="btnSave">Save</button>
|
||||
<button class="btn btn-default" id="btnDelete">Clear</button>
|
||||
<button class="btn btn-default" id="btnReload" style="float:right">Reload</button>
|
||||
|
||||
<script src="../../core/lib/interface.js"></script>
|
||||
<script>
|
||||
const dataElement = document.getElementById("data");
|
||||
let messages = "";
|
||||
|
||||
function getData() {
|
||||
// show loading window
|
||||
Util.showModal("Loading...");
|
||||
// get the data
|
||||
dataElement.innerHTML = "";
|
||||
Util.readStorageFile(`messagesdebug.log`, data => {
|
||||
messages = data.trim();
|
||||
// remove window
|
||||
Util.hideModal();
|
||||
let disable = false;
|
||||
if (data.length) {
|
||||
dataElement.innerHTML = `<pre style="overflow:auto;border:1px solid black;">${data}</pre>`;
|
||||
} else {
|
||||
dataElement.innerHTML = "<b>No messages found</b>";
|
||||
disable = true;
|
||||
}
|
||||
['btnSave','btnDelete','btnCopy'].forEach(id=>{
|
||||
document.getElementById(id).disabled = disable;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const button = (id, fn) => document.getElementById(id).addEventListener("click", fn);
|
||||
// Save messages to file
|
||||
button("btnSave", function() {
|
||||
let a = document.createElement("a");
|
||||
let url = URL.createObjectURL(new Blob([messages], {type: "text/plain"}));
|
||||
a.href = url;
|
||||
a.download = "messagesdebug.log";
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
setTimeout(function() {
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}, 0);
|
||||
});
|
||||
// Delete the file from the watch
|
||||
button("btnDelete", function() {
|
||||
Util.showModal("Deleting...");
|
||||
Util.eraseStorageFile("messagesdebug.log", function() {
|
||||
Util.hideModal();
|
||||
getData();
|
||||
});
|
||||
});
|
||||
// Reload, in case we're e.g. using the IDE to send test messages
|
||||
button("btnReload", getData);
|
||||
|
||||
// Called when app starts
|
||||
function onInit() {
|
||||
getData();
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"id": "messagesdebug",
|
||||
"name": "Messages Debug",
|
||||
"version": "0.01",
|
||||
"description": "Write all messages to a file, for debugging purposes",
|
||||
"icon": "app.png",
|
||||
"type": "bootloader",
|
||||
"tags": "tool,system",
|
||||
"supports": ["BANGLEJS","BANGLEJS2"],
|
||||
"interface": "interface.html",
|
||||
"storage": [
|
||||
{"name":"messagesdebug.boot.js","url":"boot.js"}
|
||||
],
|
||||
"data": [{"name":"messagesdebug.log"}]
|
||||
}
|
Loading…
Reference in New Issue