| 1 |
(function(){"use strict";const n=globalThis,o="0.8.0-pwa-3",r=`desktop-mode-static-${o}`,l=`desktop-mode-runtime-${o}`,d="/desktop-mode/?offline=1",h=["assets/css/desktop.css","assets/css/variables.css","assets/css/dock.css","assets/css/windows.css","assets/images/wp-logo.png"];n.addEventListener("install",t=>{t.waitUntil(p()),n.skipWaiting()}),n.addEventListener("activate",t=>{t.waitUntil((async()=>{const s=await caches.keys();await Promise.all(s.filter(e=>!e.endsWith(o)).map(e=>caches.delete(e))),await n.clients.claim()})())}),n.addEventListener("fetch",t=>{const s=t.request;if(s.method!=="GET")return;const e=new URL(s.url);if(e.origin!==n.location.origin)return;const i=e.pathname.startsWith("/desktop-mode/"),c=e.pathname.startsWith("/wp-admin/"),a=e.pathname.includes("/wp-content/plugins/desktop-mode/");if(!(!i&&!c&&!a)){if(a&&w(e.pathname)){t.respondWith(m(s));return}if(a&&f(e.pathname)){t.respondWith(g(s));return}s.mode==="navigate"&&s.destination==="document"&&t.respondWith(k(s))}}),n.addEventListener("push",t=>{t.waitUntil(Promise.resolve())}),n.addEventListener("notificationclick",t=>{t.notification.close(),t.waitUntil((async()=>{const s=t.notification.data?.url??"/desktop-mode/",i=(await n.clients.matchAll({type:"window",includeUncontrolled:!0})).find(c=>c.url.includes("/desktop-mode/"));if(i){typeof i.focus=="function"&&await i.focus();return}n.clients.openWindow&&await n.clients.openWindow(s)})())});async function p(){try{const t=await caches.open(r),s=u();await t.addAll(h.map(e=>s+e))}catch{}}function u(){const s=n.location.pathname.indexOf("/desktop-mode/"),e=n.location.origin;return s>=0,e+"/wp-content/plugins/desktop-mode/"}function f(t){return/\.(css|png|jpg|jpeg|svg|webp|woff2?|ttf|gif|ico)$/i.test(t)}function w(t){return/\.js$/i.test(t)}async function m(t){const s=await caches.open(l);try{const e=await fetch(t.url,{cache:"reload"});return e&&e.status===200&&s.put(t,e.clone()).catch(()=>{}),e}catch{const e=await s.match(t);return e||new Response("",{status:504})}}async function g(t){const s=await caches.open(l),e=await s.match(t),i=fetch(t).then(a=>(a&&a.status===200&&s.put(t,a.clone()).catch(()=>{}),a)).catch(()=>{});if(e)return e;const c=await i;return c||new Response("",{status:504})}async function k(t){try{return await fetch(t)}catch{const e=await(await caches.open(r)).match(d);return e||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"}})}}})(); |