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);
      })
  );
});