diff --git a/apps/gpstrek/ChangeLog b/apps/gpstrek/ChangeLog index 5560f00bc..2f1a9ce45 100644 --- a/apps/gpstrek/ChangeLog +++ b/apps/gpstrek/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Make selection of background activity more explicit diff --git a/apps/gpstrek/README.md b/apps/gpstrek/README.md index eecf4d087..439b7497a 100644 --- a/apps/gpstrek/README.md +++ b/apps/gpstrek/README.md @@ -39,5 +39,9 @@ If the compass fallback starts to show unreliable values, you can reset the cali ## Widget -The widget keeps the sensors alive and records some very basic statics when the app is not started. -This uses a lot of power so ensure to stop the app if you are not actively using it. +The widget keeps the sensors alive and records some very basic statistics when the app is not started. It shows as the app icon in the widget bar when the background task is active. +This uses a lot of power so ensure to stop the app if you are not actively using it. + +# Creator + +[halemmerich](https://github.com/halemmerich) diff --git a/apps/gpstrek/app.js b/apps/gpstrek/app.js index 091c407fb..0c3579d4b 100644 --- a/apps/gpstrek/app.js +++ b/apps/gpstrek/app.js @@ -6,8 +6,8 @@ if (showWidgets){ Bangle.loadWidgets(); } -let state = WIDGETS["gpstrek"].getState(); -WIDGETS["gpstrek"].start(); +let state = WIDGETS.gpstrek.getState(); +WIDGETS.gpstrek.start(false); function parseNumber(toParse){ if (toParse.includes(".")) return parseFloat(toParse); @@ -582,6 +582,18 @@ function showWaypointMenu(){ E.showMenu(menu); } +function showBackgroundMenu(){ + let menu = { + "" : { + "title" : "Background", + back : showMenu, + }, + "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {WIDGETS.gpstrek.start(true); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS.gpstrek.stop(true); removeMenu();} else {E.showMenu(mainmenu);}});}, + }; + E.showMenu(menu); +} + function showMenu(){ var mainmenu = { "" : { @@ -590,10 +602,9 @@ function showMenu(){ }, "Route" : showRouteMenu, "Waypoint" : showWaypointMenu, + "Background" : showBackgroundMenu, "Calibration": showCalibrationMenu, - "Start" : ()=>{ E.showPrompt("Start?").then((v)=>{ if (v) {state.active = true; removeMenu();} else {E.showMenu(mainmenu);}});}, - "Stop" : ()=>{ E.showPrompt("Stop?").then((v)=>{ if (v) {WIDGETS["gpstrek"].stop(); removeMenu();} else {E.showMenu(mainmenu);}});}, - "Reset" : ()=>{ E.showPrompt("Do Reset?").then((v)=>{ if (v) {WIDGETS["gpstrek"].resetState(); removeMenu();} else {E.showMenu(mainmenu);}});}, + "Reset" : ()=>{ E.showPrompt("Do Reset?").then((v)=>{ if (v) {WIDGETS.gpstrek.resetState(); removeMenu();} else {E.showMenu(mainmenu);}});}, "Slices" : { value : numberOfSlices, min:1,max:6,step:1, diff --git a/apps/gpstrek/metadata.json b/apps/gpstrek/metadata.json index 5168c870e..67f71566e 100644 --- a/apps/gpstrek/metadata.json +++ b/apps/gpstrek/metadata.json @@ -1,7 +1,7 @@ { "id": "gpstrek", "name": "GPS Trekking", - "version": "0.01", + "version": "0.02", "description": "Helper for tracking the status/progress during hiking. Do NOT depend on this for navigation!", "icon": "icon.png", "screenshots": [{"url":"screen1.png"},{"url":"screen2.png"},{"url":"screen3.png"},{"url":"screen4.png"}], @@ -13,5 +13,6 @@ {"name":"gpstrek.app.js","url":"app.js"}, {"name":"gpstrek.wid.js","url":"widget.js"}, {"name":"gpstrek.img","url":"app-icon.js","evaluate":true} - ] + ], + "data": [{"name":"gpstrek.state.json"}] } diff --git a/apps/gpstrek/widget.js b/apps/gpstrek/widget.js index bba1298d0..8d9831e06 100644 --- a/apps/gpstrek/widget.js +++ b/apps/gpstrek/widget.js @@ -1,6 +1,7 @@ (() => { const STORAGE=require('Storage'); let state = STORAGE.readJSON("gpstrek.state.json")||{}; +let bgChanged = false; function saveState(){ state.saved = Date.now(); @@ -8,7 +9,7 @@ function saveState(){ } E.on("kill",()=>{ - if (state.active){ + if (bgChanged){ saveState(); } }); @@ -72,7 +73,7 @@ function onPressure(e) { } } -function start(){ +function start(bg){ Bangle.on('GPS', onGPS); Bangle.on("HRM", onPulse); Bangle.on("mag", onMag); @@ -83,13 +84,20 @@ function start(){ Bangle.setHRMPower(1, "gpstrek"); Bangle.setCompassPower(1, "gpstrek"); Bangle.setBarometerPower(1, "gpstrek"); - state.active = true; + if (bg){ + if (!state.active) bgChanged = true; + state.active = true; + saveState(); + } Bangle.drawWidgets(); } -function stop(){ - state.active = false; - saveState(); +function stop(bg){ + if (bg){ + if (state.active) bgChanged = true; + state.active = false; + saveState(); + } Bangle.drawWidgets(); } @@ -107,7 +115,7 @@ if (state.saved && state.saved < Date.now() - 60000){ } if (state.active){ - start(); + start(false); } WIDGETS["gpstrek"]={