Automatically create new track if the filename is different

pull/2837/head
Gordon Williams 2023-06-22 13:43:22 +01:00
parent b469521f90
commit e5ebbf0ed4
3 changed files with 10 additions and 6 deletions

View File

@ -32,4 +32,5 @@
0.24: Can now specify `setRecording(true, {force:...` to not show a menu
0.25: Widget now has `isRecording()` for retrieving recording status.
0.26: Now record filename based on date
0.27: Fix first ever recorded filename being log0 (now all are dated)
0.27: Fix first ever recorded filename being log0 (now all are dated)
0.28: Automatically create new track if the filename is different

View File

@ -2,7 +2,7 @@
"id": "recorder",
"name": "Recorder",
"shortName": "Recorder",
"version": "0.27",
"version": "0.28",
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png",
"tags": "tool,outdoors,gps,widget",

View File

@ -241,9 +241,12 @@
options = options||{};
if (isOn && !settings.recording) {
var date=(new Date()).toISOString().substr(0,10).replace(/-/g,""), trackNo=10;
if (!settings.file) { // if no filename set
settings.file = "recorder.log" + date + trackNo.toString(36) + ".csv";
} else if (require("Storage").list(settings.file).length){ // if file exists
function getTrackFilename() { return "recorder.log" + date + trackNo.toString(36) + ".csv"; }
if (!settings.file || !settings.file.startsWith("recorder.log" + date)) {
// if no filename set or date different, set up a new filename
settings.file = getTrackFilename();
}
if (require("Storage").list(settings.file).length){ // if file exists
if (!options.force) { // if not forced, ask the question
g.reset(); // work around bug in 2v17 and earlier where bg color wasn't reset
return E.showPrompt(
@ -266,7 +269,7 @@
// new file - use the current date
var newFileName;
do { // while a file exists, add one to the letter after the date
newFileName = "recorder.log" + date + trackNo.toString(36) + ".csv";
newFileName = getTrackFilename();
trackNo++;
} while (require("Storage").list(newFileName).length);
settings.file = newFileName;