VoxDei
WORSHIP | PLUS GÊNESIS
🔄
Nova versão disponível
Toque em Atualizar para aplicar as melhorias
✕
// ── SISTEMA DE ATUALIZAÇÃO AUTOMÁTICA ───────────────────────
var swRegistration = null;
var swAtualizacaoPendente = false;
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('/sw.js')
.then(function(reg) {
swRegistration = reg;
if (reg.waiting) mostrarBannerUpdate();
reg.addEventListener('updatefound', function() {
var novoSW = reg.installing;
if (!novoSW) return;
novoSW.addEventListener('statechange', function() {
if (novoSW.state === 'installed' && navigator.serviceWorker.controller) {
mostrarBannerUpdate();
}
});
});
setInterval(function() { reg.update(); }, 60000);
})
.catch(function(e) { console.log('SW error:', e); });
navigator.serviceWorker.addEventListener('controllerchange', function() {
if (swAtualizacaoPendente) window.location.reload();
});
});
}
function mostrarBannerUpdate() {
var banner = document.getElementById('update-banner');
if (banner) banner.classList.add('show');
}
function fecharBannerUpdate() {
var banner = document.getElementById('update-banner');
if (banner) banner.classList.remove('show');
}
function aplicarAtualizacao() {
swAtualizacaoPendente = true;
if (swRegistration && swRegistration.waiting) {
swRegistration.waiting.postMessage({ tipo: 'skipWaiting' });
} else {
window.location.reload(true);
}
}
function recarregarApp() {
if (swRegistration) {
swRegistration.update().then(function() {
if (swRegistration.waiting) {
mostrarBannerUpdate();
} else {
toast('✓ Você já está na versão mais recente!');
}
});
} else {
window.location.reload();
}
}