Skip to content

Commit

Permalink
Automatically create new track if the filename is different
Browse files Browse the repository at this point in the history
  • Loading branch information
gfwilliams committed Jun 22, 2023
1 parent b469521 commit e5ebbf0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion apps/recorder/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion apps/recorder/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions apps/recorder/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down

0 comments on commit e5ebbf0

Please sign in to comment.