From a5b2b792df67bce6e3f4f3bfd104953a361d67ac Mon Sep 17 00:00:00 2001 From: strukturart Date: Wed, 19 Jul 2023 23:47:52 +0200 Subject: [PATCH] gps lock --- application/assets/js/keepalive.js | 12 ++++---- application/assets/js/module.js | 19 +++++++----- application/index.html | 15 +++++----- application/index.js | 48 +++++++++++++++--------------- docs/assets/js/keepalive.js | 12 ++++---- docs/assets/js/module.js | 19 +++++++----- docs/index.html | 15 +++++----- docs/index.js | 48 +++++++++++++++--------------- 8 files changed, 96 insertions(+), 92 deletions(-) diff --git a/application/assets/js/keepalive.js b/application/assets/js/keepalive.js index 3789c624..eb16818c 100644 --- a/application/assets/js/keepalive.js +++ b/application/assets/js/keepalive.js @@ -115,16 +115,16 @@ const keepalive = (() => { //reset alarm or stop loop navigator.mozSetMessageHandler("alarm", function (message) { + let k = JSON.parse(localStorage.getItem("status")); + remove_alarm(); //stop alarm when tracking is not active - let k = JSON.parse(localStorage.getItem("status")); if (k.tracking_running === false) return false; - let f = Math.round(Date.now() / 1000) - k.gps_data_received; - //module.pushLocalNotification("O.map", String(f)); - if (k.tracking_running && k.closedByUser === false) { - m(); - } else if (k.tracking_running && f > 360) { + m(); + //let f = Math.round(Date.now() / 1000) - k.gps_data_received; + //something is wrong + if (k.tracking_running && k.closedByUser == false) { module.pushLocalNotification( "O.map", "Attention the tracking was aborted unexpectedly" diff --git a/application/assets/js/module.js b/application/assets/js/module.js index 978bd317..fc3c22aa 100644 --- a/application/assets/js/module.js +++ b/application/assets/js/module.js @@ -375,6 +375,10 @@ const module = (() => { gpx_group.eachLayer(function (l) { if (l.getBounds()) gpx_selection.push(l); }); + if (gpx_selection.length == 0) { + helper.side_toaster("no gpx file to select", 2000); + return false; + } if (gpx_selection_count > gpx_selection.length - 1) gpx_selection_count = 0; map.fitBounds(gpx_selection[gpx_selection_count].getBounds()); @@ -400,6 +404,7 @@ const module = (() => { gpx_selection_info.name = gpx_selection[gpx_selection_count]._info.name; update_gpx_info(); + status.select_gpx = true; }; let update_gpx_info = function () { @@ -430,8 +435,6 @@ const module = (() => { let k = L.GeometryUtil.closest(map, m, latlng, true); - // L.marker(k).addTo(map); - let f = calc_distance( mainmarker.device_lat, mainmarker.device_lng, @@ -446,7 +449,6 @@ const module = (() => { if (mainmarker.accuracy < 22) { // Add the current value of f to the closest_average array closest_average.push(f); - console.log(closest_average); } // Calculate the average of the closest_average array if it has more than 48 elements @@ -468,10 +470,11 @@ const module = (() => { // If the average is above 0.5, trigger a vibration and show a toaster message if (result > 0.5) { - helper.side_toaster("Too far " + result, 3000); - try { - navigator.vibrate([1000, 500, 1000]); + module.pushLocalNotification( + "O.map", + "Attention you have left the path" + ); } catch (e) {} } } @@ -650,7 +653,7 @@ const module = (() => { let tracking_latlngs = []; let tracking_interval; let tracking_cache = []; - let gps_lock; + //let gps_lock; let tracking_altitude = []; let calc = 0; @@ -702,7 +705,7 @@ const module = (() => { status.tracking_running = true; if ("requestWakeLock" in navigator) { - gps_lock = window.navigator.requestWakeLock("gps"); + // gps_lock = window.navigator.requestWakeLock("gps"); if (setting.tracking_screenlock) screenWakeLock("lock", "screen"); } diff --git a/application/index.html b/application/index.html index 23ab6538..83c14f01 100644 --- a/application/index.html +++ b/application/index.html @@ -467,19 +467,19 @@

Export