From 7ffae69275ae3971dec721c2bcb887d54662a215 Mon Sep 17 00:00:00 2001 From: marsalva Date: Tue, 24 Mar 2026 21:14:32 +0000 Subject: [PATCH] Actualizar js/layout.js --- js/layout.js | 84 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 33 deletions(-) diff --git a/js/layout.js b/js/layout.js index 52c208e..7b8af80 100644 --- a/js/layout.js +++ b/js/layout.js @@ -4,43 +4,61 @@ ... */ // ========================================== -// RASTREADOR FANTASMA GPS (MODO DE CAMINO) +// 🎨 INYECTOR DE LOGO CORPORATIVO Y PWA (ICONOS APP) // ========================================== -setInterval(async () => { - if (!localStorage.getItem("token") || localStorage.getItem("role") !== "operario") return; +setTimeout(async () => { + if (!localStorage.getItem("token")) return; - const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' - ? 'http://localhost:3000' - : 'https://integrarepara-api.integrarepara.es'; - try { - const resSt = await fetch(`${TRACK_API}/statuses`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); - const dataSt = await resSt.json(); - if (!dataSt.ok) return; + const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1' + ? 'http://localhost:3000' + : 'https://integrarepara-api.integrarepara.es'; + + const res = await fetch(`${TRACK_API}/config/company`, { + headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } + }); + const data = await res.json(); - const caminoSt = dataSt.statuses.find(s => s.name.toLowerCase().includes('camino')); - if (!caminoSt) return; + if (data.ok && data.config && data.config.company_logo) { + const logoUrl = data.config.company_logo; - const resSvc = await fetch(`${TRACK_API}/services/active`, { headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` } }); - const dataSvc = await resSvc.json(); - if (!dataSvc.ok) return; - - const enRuta = dataSvc.services.filter(s => String(s.raw_data?.status_operativo) === String(caminoSt.id)); - - if (enRuta.length > 0) { - // Alta velocidad activada (enableHighAccuracy: false) - navigator.geolocation.getCurrentPosition(async (pos) => { - const lat = pos.coords.latitude; - const lng = pos.coords.longitude; + // 1. INYECTAR EN LA CABECERA (Reemplaza la letra naranja por el logo) + const headerIcon = document.querySelector('header .w-10.h-10.rounded-xl, #header-container .w-10.h-10'); + if (headerIcon) { + headerIcon.innerHTML = ''; + headerIcon.className = "w-10 h-10 flex shrink-0 items-center justify-center"; + headerIcon.style.background = "transparent"; + headerIcon.style.boxShadow = "none"; - for (let s of enRuta) { - await fetch(`${TRACK_API}/services/${s.id}/location`, { - method: 'POST', - headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("token")}` }, - body: JSON.stringify({ lat, lng }) - }); - } - }, () => {}, { enableHighAccuracy: false, timeout: 10000, maximumAge: 30000 }); + const img = document.createElement('img'); + img.src = logoUrl; + img.className = "max-w-full max-h-full object-contain drop-shadow-sm"; + headerIcon.appendChild(img); + } + + // 2. INYECTAR ICONO DE APP (Favicon para PC y Android) + let favicon = document.querySelector("link[rel~='icon']"); + if (!favicon) { + favicon = document.createElement('link'); + favicon.rel = 'icon'; + document.head.appendChild(favicon); + } + favicon.href = logoUrl; + + // 3. INYECTAR ICONO DE iPHONE (Apple Touch Icon) + // Esto le dice a Safari qué foto usar si le dan a "Añadir a la pantalla de inicio" + let appleIcon = document.querySelector("link[rel='apple-touch-icon']"); + if (!appleIcon) { + appleIcon = document.createElement('link'); + appleIcon.rel = 'apple-touch-icon'; + document.head.appendChild(appleIcon); + } + appleIcon.href = logoUrl; } - } catch (e) { } -}, 15000); // Se ejecuta cada 15 segundos + } catch (e) { + console.error("No se pudo cargar la configuración visual de la empresa", e); + } +}, 300); // Pequeño retraso para dejar que el HTML se dibuje primero + +// 🛑 RASTREADOR FANTASMA GPS (MODO DE CAMINO) DESACTIVADO TEMPORALMENTE 🛑 +// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS) \ No newline at end of file