From bbf14803b493cfbec57fed8ebf13fc92bd5f1982 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:04:34 +0000 Subject: [PATCH 1/4] Initial plan From 3374e4fb1f7c2143c0eb51f88f33e0bb128638ea Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:08:17 +0000 Subject: [PATCH 2/4] Update map refresh logic and status messages per requirements Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com> --- content/wardrive.js | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/content/wardrive.js b/content/wardrive.js index fc6a12a..d7fa9d2 100644 --- a/content/wardrive.js +++ b/content/wardrive.js @@ -110,7 +110,7 @@ function buildCoverageEmbedUrl(lat, lon) { return `${base}&lat=${encodeURIComponent(lat)}&lon=${encodeURIComponent(lon)}`; } let coverageRefreshTimer = null; -function scheduleCoverageRefresh(lat, lon) { +function scheduleCoverageRefresh(lat, lon, delayMs = 0) { if (!coverageFrameEl) return; if (coverageRefreshTimer) clearTimeout(coverageRefreshTimer); @@ -119,7 +119,7 @@ function scheduleCoverageRefresh(lat, lon) { const url = buildCoverageEmbedUrl(lat, lon); console.log("Coverage iframe URL:", url); coverageFrameEl.src = url; - }, 5000); + }, delayMs); } function setConnectButton(connected) { if (!connectBtn) return; @@ -464,23 +464,39 @@ async function sendPing(manual = false) { // Start cooldown period after successful ping startCooldown(); + const nowStr = new Date().toLocaleString(); + setStatus(manual ? "Ping sent" : "Auto ping sent", "text-emerald-300"); + // Schedule MeshMapper API call with 7-second delay (non-blocking) // Clear any existing timer first if (state.meshMapperTimer) { clearTimeout(state.meshMapperTimer); } - state.meshMapperTimer = setTimeout(() => { - postToMeshMapperAPI(lat, lon); + + // Update status to show we're waiting to post to API + setTimeout(() => { + if (state.connection) { + setStatus("Waiting to post to API", "text-sky-300"); + } + }, 100); // Small delay to ensure "Ping sent" is visible first + + state.meshMapperTimer = setTimeout(async () => { + await postToMeshMapperAPI(lat, lon); + + // Update map 1 second after API post to ensure backend updated + setTimeout(() => { + if (accuracy && accuracy < GPS_ACCURACY_THRESHOLD_M) { + scheduleCoverageRefresh(lat, lon); + } + + // Set status to idle after map update + if (state.connection) { + setStatus("Idle", "text-slate-300"); + } + }, 1000); + state.meshMapperTimer = null; }, MESHMAPPER_DELAY_MS); - - // Only refresh coverage iframe if GPS accuracy is good - if (accuracy && accuracy < GPS_ACCURACY_THRESHOLD_M) { - scheduleCoverageRefresh(lat, lon); - } - - const nowStr = new Date().toLocaleString(); - setStatus(manual ? "Ping sent" : "Auto ping sent", "text-emerald-300"); if (lastPingEl) lastPingEl.textContent = `${nowStr} — ${payload}`; // Session log From 632862710148bcc363ed4e084f592ae9875bfb6a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:10:30 +0000 Subject: [PATCH 3/4] Address code review: Extract magic numbers to named constants Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com> --- content/wardrive.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/content/wardrive.js b/content/wardrive.js index d7fa9d2..4a10f5f 100644 --- a/content/wardrive.js +++ b/content/wardrive.js @@ -15,6 +15,8 @@ const GPS_FRESHNESS_BUFFER_MS = 5000; // Buffer time for GPS freshness const GPS_ACCURACY_THRESHOLD_M = 100; // Maximum acceptable GPS accuracy in meters const MESHMAPPER_DELAY_MS = 7000; // Delay MeshMapper API call by 7 seconds const COOLDOWN_MS = 7000; // Cooldown period for manual ping and auto toggle +const STATUS_UPDATE_DELAY_MS = 100; // Brief delay to ensure "Ping sent" status is visible +const MAP_REFRESH_DELAY_MS = 1000; // Delay after API post to ensure backend updated const WARDROVE_KEY = new Uint8Array([ 0x40, 0x76, 0xC3, 0x15, 0xC1, 0xEF, 0x38, 0x5F, 0xA9, 0x3F, 0x06, 0x60, 0x27, 0x32, 0x0F, 0xE5 @@ -464,7 +466,6 @@ async function sendPing(manual = false) { // Start cooldown period after successful ping startCooldown(); - const nowStr = new Date().toLocaleString(); setStatus(manual ? "Ping sent" : "Auto ping sent", "text-emerald-300"); // Schedule MeshMapper API call with 7-second delay (non-blocking) @@ -478,12 +479,12 @@ async function sendPing(manual = false) { if (state.connection) { setStatus("Waiting to post to API", "text-sky-300"); } - }, 100); // Small delay to ensure "Ping sent" is visible first + }, STATUS_UPDATE_DELAY_MS); state.meshMapperTimer = setTimeout(async () => { await postToMeshMapperAPI(lat, lon); - // Update map 1 second after API post to ensure backend updated + // Update map after API post to ensure backend updated setTimeout(() => { if (accuracy && accuracy < GPS_ACCURACY_THRESHOLD_M) { scheduleCoverageRefresh(lat, lon); @@ -493,10 +494,12 @@ async function sendPing(manual = false) { if (state.connection) { setStatus("Idle", "text-slate-300"); } - }, 1000); + }, MAP_REFRESH_DELAY_MS); state.meshMapperTimer = null; }, MESHMAPPER_DELAY_MS); + + const nowStr = new Date().toLocaleString(); if (lastPingEl) lastPingEl.textContent = `${nowStr} — ${payload}`; // Session log From 6d7cf31a3e0410aaa9b4cbc9f8aa10b99576b03e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 17 Dec 2025 21:11:40 +0000 Subject: [PATCH 4/4] Add error handling and fix accuracy variable closure Co-authored-by: MrAlders0n <55921894+MrAlders0n@users.noreply.github.com> --- content/wardrive.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/content/wardrive.js b/content/wardrive.js index 4a10f5f..a50d999 100644 --- a/content/wardrive.js +++ b/content/wardrive.js @@ -482,11 +482,19 @@ async function sendPing(manual = false) { }, STATUS_UPDATE_DELAY_MS); state.meshMapperTimer = setTimeout(async () => { - await postToMeshMapperAPI(lat, lon); + // Capture accuracy in closure to ensure it's available in nested callback + const capturedAccuracy = accuracy; + + try { + await postToMeshMapperAPI(lat, lon); + } catch (error) { + console.error("MeshMapper API post failed:", error); + // Continue with map refresh and status update even if API fails + } // Update map after API post to ensure backend updated setTimeout(() => { - if (accuracy && accuracy < GPS_ACCURACY_THRESHOLD_M) { + if (capturedAccuracy && capturedAccuracy < GPS_ACCURACY_THRESHOLD_M) { scheduleCoverageRefresh(lat, lon); }