feat(ui): зелёная кнопка ответа и автообновление PWA

This commit is contained in:
AidarKC
2026-04-22 19:49:32 +03:00
parent e0333a9c32
commit 1a8d1c70fd
5 changed files with 200 additions and 2 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ function ensureUi() {
acceptBtn = document.createElement('button');
acceptBtn.type = 'button';
acceptBtn.className = 'primary-btn';
acceptBtn.className = 'call-accept-btn';
acceptBtn.textContent = 'Ответить';
acceptBtn.addEventListener('click', async () => {
await acceptIncomingCall();
+49 -1
View File
@@ -1,4 +1,49 @@
const LS_KEY = 'shine-ui-webpush-subscription-v1';
const SW_UPDATE_CHECK_INTERVAL_MS = 5 * 60 * 1000;
let swUpdateIntervalId = null;
let controllerChangeHandled = false;
function setupServiceWorkerAutoUpdate(registration, log) {
if (!registration) return;
if (!controllerChangeHandled && 'serviceWorker' in navigator) {
controllerChangeHandled = true;
navigator.serviceWorker.addEventListener('controllerchange', () => {
log({
level: 'info',
source: 'web-push',
message: 'Service Worker обновился, перезагружаем UI',
});
window.location.reload();
});
}
registration.addEventListener('updatefound', () => {
const installing = registration.installing;
if (!installing) return;
log({
level: 'info',
source: 'web-push',
message: 'Найдено обновление Service Worker',
});
});
if (swUpdateIntervalId) {
window.clearInterval(swUpdateIntervalId);
swUpdateIntervalId = null;
}
const checkNow = () => {
registration.update().catch(() => {});
};
checkNow();
swUpdateIntervalId = window.setInterval(checkNow, SW_UPDATE_CHECK_INTERVAL_MS);
document.addEventListener('visibilitychange', () => {
if (document.visibilityState !== 'visible') return;
checkNow();
});
}
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
@@ -36,13 +81,16 @@ export async function initPwaPush({ authService, onLog = null }) {
}
try {
const registration = await navigator.serviceWorker.register('./firebase-messaging-sw.js');
const registration = await navigator.serviceWorker.register('./firebase-messaging-sw.js', {
updateViaCache: 'none',
});
log({
level: 'info',
source: 'web-push',
message: 'Service Worker зарегистрирован',
details: { scope: registration.scope },
});
setupServiceWorkerAutoUpdate(registration, log);
const permission = await Notification.requestPermission();
if (permission !== 'granted') {