Spaces:
Running
Running
File size: 2,227 Bytes
85f7eb5 c9d6ddb 85f7eb5 c9d6ddb 36195bf 6a3a094 85f7eb5 6a3a094 85f7eb5 6a3a094 cd05f5e 85f7eb5 6a3a094 85f7eb5 c9d6ddb 36195bf 85f7eb5 6a3a094 c9d6ddb 85f7eb5 6a3a094 c9d6ddb 85f7eb5 36195bf c9d6ddb 85f7eb5 cd05f5e 85f7eb5 6a3a094 85f7eb5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | /* ======================================================
VIDRAFT Service Worker β Web Push Notifications v4
v3μμ .catch() μ²΄μΈ μ κ±° (λͺ¨λ°μΌ silent-fail μμΈ)
Windows νΈν: actions μ κ±° μ μ§
====================================================== */
const CACHE_VERSION = 'vidraft-sw-v4';
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', e => e.waitUntil(self.clients.claim()));
// ββ Push μμ β μλ¦Ό νμ ββββββββββββββββββββββββββββ
self.addEventListener('push', (e) => {
let d = {
title: 'VIDRAFT',
body: 'μ μμμ΄ μμ΅λλ€.',
icon: 'https://vidraft-ai.static.hf.space/favicon.png',
badge: 'https://vidraft-ai.static.hf.space/favicon.png',
image: '',
url: 'https://vidraft.net'
};
if (e.data) {
try { d = { ...d, ...e.data.json() }; }
catch { d.body = e.data.text(); }
}
console.log('[SW v4] push received, title:', d.title);
const options = {
body: d.body,
icon: d.icon,
badge: d.badge,
tag: 'vidraft-push',
renotify: true,
requireInteraction: false,
data: { url: d.url },
// actions μ κ±° β Windows Chrome silent-fail μ λ°
};
if (d.image && d.image.trim()) {
options.image = d.image.trim();
}
// .catch() μ²΄μΈ μμ΄ μ§μ waitUntil β κ°μ₯ μμ μ
e.waitUntil(self.registration.showNotification(d.title, options));
});
// ββ μλ¦Ό ν΄λ¦ β ν μ΄κΈ° βββββββββββββββββββββββββββββ
self.addEventListener('notificationclick', (e) => {
e.notification.close();
const target = (e.notification.data && e.notification.data.url)
? e.notification.data.url
: 'https://vidraft.net';
e.waitUntil(
self.clients.matchAll({ type: 'window', includeUncontrolled: true })
.then(clients => {
for (const c of clients) {
if (c.url === target && 'focus' in c) return c.focus();
}
if (self.clients.openWindow) return self.clients.openWindow(target);
})
);
});
|