fix(02-review): WR-02 stop MeshMap geolocation watch on deactivate, resume on activate

onDeactivated only tore down the resize listener/ResizeObserver, not the
navigator.geolocation.watchPosition watch started by "Share Location" —
leaving GPS polling running in the background (battery drain, active
location indicator) for as long as the KeepAlive'd component survives,
instead of only while the Mesh tab is visible like every other resource
this phase added only-while-visible handling for in this file.

onDeactivated now stops an active watch (tracked via a flag rather than
losing the user's toggle state), and onActivated transparently resumes it
on return to the tab.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
archipelago
2026-07-31 04:17:38 -04:00
co-authored by Claude
parent 6105770420
commit 751b05f271
+17 -1
View File
@@ -421,12 +421,28 @@ function disarmMapVisibility() {
// count as the first activation's arm, so onActivated only re-arms on a
// genuine later reactivation, matching Mesh.vue's own meshFreshMount idiom.
let mapMountFresh = true
// Set when a live geolocation watch is torn down by onDeactivated so
// onActivated can transparently resume it (WR-02) — the browser location
// watch must not keep firing (battery drain, background location indicator)
// while the Mesh tab is off screen, matching the only-while-visible pattern
// already applied to the resize listener/ResizeObserver in this file.
let wasSharingBeforeDeactivate = false
onActivated(() => {
if (mapMountFresh) { mapMountFresh = false; return }
armMapVisibility()
if (wasSharingBeforeDeactivate) {
wasSharingBeforeDeactivate = false
startSharing()
}
})
onMounted(() => armMapVisibility())
onDeactivated(() => disarmMapVisibility())
onDeactivated(() => {
disarmMapVisibility()
if (sharingLocation.value) {
wasSharingBeforeDeactivate = true
stopSharing()
}
})
onUnmounted(() => {
disarmMapVisibility()