BangleApps/apps/gipy/interface.html

70 lines
2.0 KiB
HTML
Raw Normal View History

2022-11-07 13:03:15 +00:00
<html>
<head>
<link rel="stylesheet" href="../../css/spectre.min.css">
</head>
<body>
<p>Please select a gpx file to be converted to gpc and loaded.</p>
<input type="file" is="gpx_file" id="fileInput" accept=".gpx">
<script src="../../core/lib/interface.js"></script>
2022-11-07 13:03:15 +00:00
<script type="module">
2022-11-08 07:37:09 +00:00
function uploadFile(fileid, contents) {
// TODO: use interface.js-provided stuff?
Puck.write(`\x10(function() {
2022-11-08 07:50:21 +00:00
require("Storage").write("${JSON.stringify(fileid)}",'${JSON.stringify(contents)}');
2022-11-08 07:37:09 +00:00
Bluetooth.print("OK");
})()\n`, ret => {
console.log("uploadFile", ret);
if (ret == "OK")
clean();
});
}
function onInit() {
}
2022-11-07 13:03:15 +00:00
import init, { convert_gpx_strings } from "./pkg/gpconv.js";
console.log("imported wasm");
document.getElementById('fileInput').addEventListener('change', function selectedFileChanged() {
if (this.files.length === 0) {
console.log('No file selected.');
return;
}
let gpx_filename = this.files[0].name;
let gpc_filename = gpx_filename.slice(0, gpx_filename.length-4) + ".gpc";
while (gpc_filename.length > 28) {
let new_name = prompt("enter a shorter destination filename than '" + gpc_filename + "' (28 chars max)", gpc_filename);
if (new_name != null && new_name.slice(new_name.length-4) == ".gpc") {
gpc_filename = new_name;
} else {
return;
}
}
const reader = new FileReader();
reader.onload = function fileReadCompleted() {
console.log("reading file completed");
init().then(() => {
let gpc_file = convert_gpx_strings(reader.result);
let gpc_string = String.fromCharCode.apply(String, gpc_file);
console.log("uploading");
2022-11-08 07:37:09 +00:00
uploadFile(gpc_filename, gpc_string);
2022-11-07 13:03:15 +00:00
});
}
reader.readAsText(this.files[0]);
});
</script>
</body>
</html>