diff --git a/apps/recorder/interface.html b/apps/recorder/interface.html
index 1f11b87615..dbb7969566 100644
--- a/apps/recorder/interface.html
+++ b/apps/recorder/interface.html
@@ -691,314 +691,323 @@
`;
}
-function getTrackList() {
+async function getTrackList() {
Util.showModal("Loading Track List...");
domTracks.innerHTML = "";
cleanupMaps();
cleanupCharts();
- Puck.eval(`require("Storage").list(/^recorder\\.log.*\\.csv$/,{sf:1})`,files=>{
- let trackList = [];
- // Use promise chain to load tracks sequentially - this prevents overwhelming the Bangle
- // with too many concurrent requests and ensures stable Bluetooth communication
- let promise = Promise.resolve();
-
- files.forEach(filename => {
- promise = promise.then(()=>new Promise(resolve => {
- const matches = filename.match(/^recorder\.log(.*)\.csv$/);
- const trackNo = matches ? matches[1] : '';
- Util.showModal(`Loading Track ${trackNo}...`);
- // This function runs on the Bangle to quickly scan for valid GPS data
- // Many tracks start recording before GPS lock, so we search up to 100 lines
- // to find the first coordinate for the track preview
- Puck.eval(`(function(fn) {
- var f = require("Storage").open(fn,"r");
- var headers = f.readLine().trim();
- var data = f.readLine();
- var lIdx = headers.split(",").indexOf("Latitude");
- if (lIdx >= 0) {
- var tries = 100;
- var l = data;
- while (l && l.split(",")[lIdx]==="" && tries--)
- l = f.readLine();
- if (l) data = l;
- }
- return {headers:headers,l:data};
-})(${JSON.stringify(filename)})`, trackInfo=>{
- if (!trackInfo || !("headers" in trackInfo)) {
- showToast("Error loading track list.", "error");
- resolve();
- return;
- }
- trackInfo.headers = trackInfo.headers.split(",");
- trackList.push({
- filename : filename,
- number : trackNo,
- info : trackInfo
- });
- resolve();
- });
- }));
+ const files = await new Promise(resolve => {
+ Puck.eval(`require("Storage").list(/^recorder\\.log.*\\.csv$/,{sf:1})`, resolve);
+ });
+
+ let trackList = [];
+
+ // Load tracks sequentially - don't overwhelm the Bangle with too many concurrent requests
+ let promise = Promise.resolve();
+
+ for (const filename of files) {
+ const matches = filename.match(/^recorder\.log(.*)\.csv$/);
+ const trackNo = matches ? matches[1] : '';
+
+ Util.showModal(`Loading Track ${trackNo}...`);
+
+ const trackInfo = await new Promise(resolve => {
+ // This function runs on the Bangle to quickly scan for valid GPS data
+ // Many tracks start recording before GPS lock, so we search up to 100 lines
+ // to find the first coordinate for the track preview
+ Puck.eval(`(function(fn) {
+var f = require("Storage").open(fn,"r");
+var headers = f.readLine().trim();
+var data = f.readLine();
+var lIdx = headers.split(",").indexOf("Latitude");
+if (lIdx >= 0) {
+ var tries = 100;
+ var l = data;
+ while (l && l.split(",")[lIdx]==="" && tries--)
+ l = f.readLine();
+ if (l) data = l;
+}
+return {headers:headers,l:data};
+})(${JSON.stringify(filename)})`, resolve);
});
- promise.then(() => {
- trackList.sort((a, b) => b.number.localeCompare(a.number));
-
- let html = `
-
-
GPS Tracks
`;
-
- if (trackList.length > 0) {
- html += htmlCheckbox("select-all", "Select all");
- html += `