layout.js: añade favicon dinámico (icono del logo en la pestaña)

This commit is contained in:
2026-09-13 13:07:08 +00:00
parent 07282ddc59
commit 00a0b09e20

View File

@@ -1,39 +1,45 @@
/* ...
AQUÍ ARRIBA ESTÁ TODO TU CÓDIGO ORIGINAL DEL LAYOUT
(El que dibuja el sidebar, el header, el menú, etc.)
/* ...
AQUÍ ARRIBA ESTÁ TODO TU CÓDIGO ORIGINAL DEL LAYOUT
(El que dibuja el sidebar, el header, el menú, etc.)
... */
// ==========================================
// 🎨 INYECTOR DE LOGO CORPORATIVO Y PWA (ICONOS APP)
// ==========================================
// 1. INYECCIÓN SÚPER RÁPIDA (Para engañar a los iPhone 🍏)
// Crea (o reutiliza) un <link> de icono en el <head> y le pone la URL indicada
function setIconLink(rel, href) {
let link = document.querySelector(`link[rel='${rel}']`);
if (!link) {
link = document.createElement('link');
link.rel = rel;
document.head.appendChild(link);
}
link.href = href;
}
// 1. INYECCIÓN SÚPER RÁPIDA (Para engañar a los iPhone 🍏 y pintar ya la pestaña del navegador)
// Miramos si ya tenemos el logo guardado en la memoria del móvil
const savedLogo = localStorage.getItem("company_logo");
if (savedLogo) {
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 = savedLogo;
setIconLink('apple-touch-icon', savedLogo);
setIconLink('icon', savedLogo);
}
// 2. DESCARGA DESDE EL SERVIDOR Y CABECERA
setTimeout(async () => {
if (!localStorage.getItem("token")) return;
try {
const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
? 'http://localhost:3000'
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 res = await fetch(`${TRACK_API}/config/company`, {
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
});
const data = await res.json();
if (data.ok && data.config && data.config.company_logo) {
const logoUrl = data.config.company_logo;
@@ -44,29 +50,25 @@ setTimeout(async () => {
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.className = "w-10 h-10 flex shrink-0 items-center justify-center";
headerIcon.style.background = "transparent";
headerIcon.style.boxShadow = "none";
const img = document.createElement('img');
img.src = logoUrl;
img.className = "max-w-full max-h-full object-contain drop-shadow-sm";
headerIcon.appendChild(img);
}
// Inyectamos el icono por si es la primera vez que entra
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;
// Icono de la pestaña del navegador / favicon
setIconLink('icon', logoUrl);
// Icono al añadir la app a la pantalla de inicio (iOS)
setIconLink('apple-touch-icon', logoUrl);
}
} catch (e) {
console.error("No se pudo cargar la configuración visual de la empresa", e);
}
}, 100);
}, 100);
// 🛑 RASTREADOR FANTASMA GPS (MODO DE CAMINO) DESACTIVADO TEMPORALMENTE 🛑
// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS)
// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS)