From 4fd6d9627a86b35e7d51d629ec93c3748491ba40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 9 May 2026 10:17:25 +0300 Subject: [PATCH] =?UTF-8?q?Uygulama=20e=C4=9Fer=20g=C3=BCncelleme=20varsa?= =?UTF-8?q?=20g=C3=B6sterecek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/views/version/swRegistration.ts | 89 ++++++++++++++++++++++++-- 1 file changed, 85 insertions(+), 4 deletions(-) diff --git a/ui/src/views/version/swRegistration.ts b/ui/src/views/version/swRegistration.ts index 77ac567..00a6c16 100644 --- a/ui/src/views/version/swRegistration.ts +++ b/ui/src/views/version/swRegistration.ts @@ -1,12 +1,93 @@ import { registerSW } from 'virtual:pwa-register' +function showUpdateOverlay() { + if (document.getElementById('sw-update-overlay')) return + + const style = document.createElement('style') + style.id = 'sw-update-overlay-style' + style.textContent = ` + #sw-update-overlay { + position: fixed; + inset: 0; + z-index: 99999; + display: flex; + align-items: center; + justify-content: center; + background: rgba(0, 0, 0, 0.65); + backdrop-filter: blur(4px); + -webkit-backdrop-filter: blur(4px); + } + #sw-update-overlay .sw-update-card { + display: flex; + flex-direction: column; + align-items: center; + gap: 20px; + background: #fff; + border-radius: 16px; + padding: 40px 56px; + box-shadow: 0 8px 40px rgba(0,0,0,0.25); + text-align: center; + max-width: 360px; + width: 90%; + } + #sw-update-overlay .sw-update-spinner { + width: 56px; + height: 56px; + border: 5px solid #e5e7eb; + border-top-color: #6366f1; + border-radius: 50%; + animation: sw-spin 0.8s linear infinite; + } + @keyframes sw-spin { + to { transform: rotate(360deg); } + } + #sw-update-overlay .sw-update-title { + font-size: 18px; + font-weight: 700; + color: #1f2937; + margin: 0; + } + #sw-update-overlay .sw-update-desc { + font-size: 14px; + color: #6b7280; + margin: 0; + } + ` + document.head.appendChild(style) + + const overlay = document.createElement('div') + overlay.id = 'sw-update-overlay' + overlay.innerHTML = ` +
+
+

System Updating

+

Loading new version, please wait...
The page will reload automatically.

+
+ ` + document.body.appendChild(overlay) +} + export const registerServiceWorker = () => { + // autoUpdate modunda onNeedRefresh tetiklenmez. + // updatefound → yeni SW installing → overlay aç. + // skipWaiting: true (workbox config) → controllerchange → autoUpdate reload. + if ('serviceWorker' in navigator) { + navigator.serviceWorker.ready.then((registration) => { + registration.addEventListener('updatefound', () => { + const newWorker = registration.installing + if (!newWorker) return + newWorker.addEventListener('statechange', () => { + // Yeni SW kuruldu, aktivasyon aşamasına geçiyor + if (newWorker.state === 'installed' && navigator.serviceWorker.controller) { + showUpdateOverlay() + } + }) + }) + }) + } + registerSW({ immediate: true, - onNeedRefresh() { - console.log('🔔 New version available, please refresh.') - window.location.reload() - }, onOfflineReady() { console.log('📦 App offline ready') },