| 1 |
(function(){"use strict";const n=globalThis,h="0.8.0-pwa-5",c=`os-static-${h}`,l=`os-runtime-${h}`,p="/openstation/?offline=1",f=["assets/css/desktop.css","assets/css/variables.css","assets/css/dock.css","assets/css/windows.css","assets/js/desktop.min.js","assets/js/window-system.min.js","assets/js/shell-overlays.min.js","assets/images/wp-logo.png"];n.addEventListener("install",t=>{t.waitUntil(d()),n.skipWaiting()}),n.addEventListener("activate",t=>{t.waitUntil((async()=>{const e=await caches.keys();await Promise.all(e.filter(s=>!s.endsWith(h)).map(s=>caches.delete(s))),await n.clients.claim()})())}),n.addEventListener("fetch",t=>{const e=t.request;if(e.method!=="GET")return;const s=new URL(e.url);if(s.origin!==n.location.origin)return;const i=s.pathname.startsWith("/openstation/"),a=s.pathname.startsWith("/wp-admin/"),o=s.pathname.includes("/wp-content/plugins/desktop-mode/");if(!(!i&&!a&&!o)){if(o&&g(s.pathname)){t.respondWith(y(e));return}if(o&&m(s.pathname)){t.respondWith(k(e));return}e.mode==="navigate"&&e.destination==="document"&&t.respondWith(A(e))}}),n.addEventListener("push",t=>{t.waitUntil(Promise.resolve())}),n.addEventListener("notificationclick",t=>{t.notification.close(),t.waitUntil((async()=>{const e=t.notification.data?.url??"/openstation/",i=(await n.clients.matchAll({type:"window",includeUncontrolled:!0})).find(a=>a.url.includes("/openstation/"));if(i){typeof i.focus=="function"&&await i.focus();return}n.clients.openWindow&&await n.clients.openWindow(e)})())});async function d(){try{const t=await caches.open(c),e=w();await t.addAll(f.map(s=>e+s))}catch{}}function w(){return n.location.origin+"/wp-content/plugins/desktop-mode/"}function m(t){return/\.(css|png|jpg|jpeg|svg|webp|woff2?|ttf|gif|ico)$/i.test(t)}function g(t){return/\.js$/i.test(t)}async function y(t){const e=await caches.open(l);try{const s=await fetch(t.url,{cache:"reload"});return s&&s.status===200&&e.put(t,s.clone()).catch(()=>{}),s}catch{const s=await e.match(t);if(s)return s;const a=await(await caches.open(c)).match(t,{ignoreSearch:!0});return a||new Response("",{status:504})}}async function k(t){const e=await caches.open(l),s=await e.match(t),i=fetch(t).then(r=>(r&&r.status===200&&e.put(t,r.clone()).catch(()=>{}),r)).catch(()=>{});if(s)return s;const a=await i;if(a)return a;const u=await(await caches.open(c)).match(t,{ignoreSearch:!0});return u||new Response("",{status:504})}async function A(t){try{return await fetch(t)}catch{const s=await(await caches.open(c)).match(p);return s||new Response('<!doctype html><meta charset="utf-8"><title>Offline</title><p>You appear to be offline. The app will work again as soon as the connection returns.</p>',{status:503,headers:{"Content-Type":"text/html; charset=utf-8"}})}}})(); |