Web-based Winamp controller for CarPC � Go backend, mobile-first UI
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2KB

  1. 'use strict';
  2. // Cache name is injected by build.ps1 (token replaced with git version).
  3. // When the binary is built without the script, __BUILDVER__ stays literal
  4. // and the SW still works — it just won't auto-bust on updates.
  5. const CACHE = 'roadamp-__BUILDVER__';
  6. const SHELL = ['/', '/app.js', '/style.css', '/manifest.json', '/icon.svg'];
  7. self.addEventListener('install', e => {
  8. e.waitUntil(
  9. caches.open(CACHE)
  10. .then(c => c.addAll(SHELL))
  11. .then(() => self.skipWaiting())
  12. );
  13. });
  14. self.addEventListener('activate', e => {
  15. e.waitUntil(
  16. caches.keys()
  17. .then(keys => Promise.all(
  18. keys.filter(k => k !== CACHE).map(k => caches.delete(k))
  19. ))
  20. .then(() => self.clients.claim())
  21. );
  22. });
  23. self.addEventListener('fetch', e => {
  24. const url = new URL(e.request.url);
  25. // Pass through API calls and WebSocket upgrades uncached.
  26. if (url.pathname.startsWith('/api/') || url.pathname === '/ws') return;
  27. e.respondWith(
  28. caches.match(e.request).then(cached => {
  29. if (cached) return cached;
  30. return fetch(e.request).then(res => {
  31. const clone = res.clone();
  32. caches.open(CACHE).then(c => c.put(e.request, clone));
  33. return res;
  34. });
  35. })
  36. );
  37. });