fix: robust mobile suspend and auth recovery
This commit is contained in:
@ -135,17 +135,17 @@ function closePromoModal() {
|
||||
selectedPromo.value = null;
|
||||
}
|
||||
|
||||
async function fetchData() {
|
||||
async function fetchData(isBackground = false) {
|
||||
await Promise.all([
|
||||
routeStore.loadRoutes(),
|
||||
couponStore.loadCoupons({ active_only: true })
|
||||
routeStore.loadRoutes(undefined, false, isBackground),
|
||||
couponStore.loadCoupons({ active_only: true }, isBackground)
|
||||
]);
|
||||
updateActiveUnits();
|
||||
}
|
||||
|
||||
async function handleRefocus() {
|
||||
// Refrescar datos en fondo
|
||||
fetchData();
|
||||
// Refrescar datos en fondo de manera silenciosa (isBackground = true)
|
||||
fetchData(true);
|
||||
|
||||
await nextTick();
|
||||
|
||||
@ -419,7 +419,9 @@ function locateUser(): Promise<void> {
|
||||
}
|
||||
resolve();
|
||||
},
|
||||
{ enableHighAccuracy: true, timeout: 8000, maximumAge: 30000 }
|
||||
// maximumAge: 5 min — al volver del background, usa posición cacheada inmediatamente
|
||||
// en lugar de esperar que el GPS se reactive (evita timeout al desbloquear pantalla)
|
||||
{ enableHighAccuracy: false, timeout: 6000, maximumAge: 300000 }
|
||||
);
|
||||
});
|
||||
}
|
||||
@ -515,10 +517,19 @@ function handleImageError(event: Event) {
|
||||
}
|
||||
|
||||
// Watch for user profile to trigger location if preference is enabled OR on auth changes
|
||||
watch([() => authStore.userProfile?.auto_location, isLoaded], ([canLocate, loaded]) => {
|
||||
// Nota: solo se activa si NO tenemos coordenadas aún Y el mapa está cargado.
|
||||
// Se evita re-disparar por TOKEN_REFRESHED porque onAuthStateChange ya no recarga
|
||||
// el perfil en ese evento, así que userProfile no cambia al despertar la pantalla.
|
||||
watch([() => authStore.userProfile?.auto_location, isLoaded], ([canLocate, loaded], [prevCanLocate]) => {
|
||||
// Solo localizar si: el mapa cargó, auto_location está activo,
|
||||
// y NO tenemos coords aún (o el mapa se reinicializó sin coords)
|
||||
if (canLocate && loaded && !userCoords.value) {
|
||||
console.log('SIBU | Iniciando geolocalización automática...');
|
||||
locateUser();
|
||||
// Extra guard: no re-disparar si auto_location no cambió (solo isLoaded cambió)
|
||||
// Esto previene relocalización innecesaria al volver del background
|
||||
if (prevCanLocate !== undefined || !userCoords.value) {
|
||||
console.log('SIBU | Iniciando geolocalización automática...');
|
||||
locateUser();
|
||||
}
|
||||
}
|
||||
}, { immediate: true });
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user