Fix for when recorder widget is used before app

master
Salim Blume 2022-03-14 11:07:26 -05:00
parent 7eceff5443
commit 7adfda340e
5 changed files with 19 additions and 9 deletions

View File

@ -16,3 +16,4 @@
0.10: Fix broken recorder settings (when launched from settings app)
0.11: Fix KML and GPX export when there is no GPS data
0.12: Fix 'Back' label positioning on track/graph display, make translateable
0.13: Fix for when widget is used before app

View File

@ -1,6 +1,6 @@
{
"recording":false,
"file":"record.log0.csv",
"file":"recorder.log0.csv",
"period":10,
"record" : ["gps"]
}

View File

@ -31,7 +31,12 @@ function updateSettings() {
}
function getTrackNumber(filename) {
return parseInt(filename.match(/^recorder\.log(.*)\.csv$/)[1]||0);
var trackNum = 0;
var matches = filename.match(/^recorder\.log(.*)\.csv$/);
if (matches) {
trackNum = parseInt(matches[1]||0);
}
return trackNum;
}
function showMainMenu() {

View File

@ -2,7 +2,7 @@
"id": "recorder",
"name": "Recorder",
"shortName": "Recorder",
"version": "0.12",
"version": "0.13",
"description": "Record GPS position, heart rate and more in the background, then download to your PC.",
"icon": "app.png",
"tags": "tool,outdoors,gps,widget",
@ -15,5 +15,5 @@
{"name":"recorder.wid.js","url":"widget.js"},
{"name":"recorder.settings.js","url":"settings.js"}
],
"data": [{"name":"recorder.json"},{"wildcard":"recorder.log?.csv","storageFile":true}]
"data": [{"name":"recorder.json","url":"app-settings.json"},{"wildcard":"recorder.log?.csv","storageFile":true}]
}

View File

@ -11,7 +11,7 @@
settings.recording = false;
return settings;
}
function updateSettings(settings) {
require("Storage").writeJSON("recorder.json", settings);
if (WIDGETS["recorder"]) WIDGETS["recorder"].reload();
@ -233,7 +233,9 @@
Bangle.drawWidgets(); // relayout all widgets
},setRecording:function(isOn) {
var settings = loadSettings();
if (isOn && !settings.recording && require("Storage").list(settings.file).length){
if (isOn && !settings.recording && !settings.file) {
settings.file = "recorder.log0.csv";
} else if (isOn && !settings.recording && require("Storage").list(settings.file).length){
var logfiles=require("Storage").list(/recorder.log.*/);
var maxNumber=0;
for (var c of logfiles){
@ -247,9 +249,11 @@
var buttons={Yes:"yes",No:"no"};
if (newFileName) buttons["New"] = "new";
var prompt = E.showPrompt("Overwrite\nLog " + settings.file.match(/\d+/)[0] + "?",{title:"Recorder",buttons:buttons}).then(selection=>{
if (selection=="no") return false; // just cancel
if (selection=="yes") require("Storage").open(settings.file,"r").erase();
if (selection=="new"){
if (selection==="no") return false; // just cancel
if (selection==="yes") {
require("Storage").open(settings.file,"r").erase();
}
if (selection==="new"){
settings.file = newFileName;
updateSettings(settings);
}