| 1 |
(function(){"use strict";const a=globalThis,h="0.8.0-pwa-5",i=`desktop-mode-static-${h}`,l=`desktop-mode-runtime-${h}`,u="/desktop-mode/?offline=1",p=["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"];a.addEventListener("install",t=>{t.waitUntil(f()),a.skipWaiting()}),a.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 a.clients.claim()})())}),a.addEventListener("fetch",t=>{const e=t.request;if(e.method!=="GET")return;const s=new URL(e.url);if(s.origin!==a.location.origin)return;const c=s.pathname.startsWith("/desktop-mode/"),n=s.pathname.startsWith("/wp-admin/"),o=s.pathname.includes("/wp-content/plugins/desktop-mode/");if(!(!c&&!n&&!o)){if(o&&g(s.pathname)){t.respondWith(k(e));return}if(o&&m(s.pathname)){t.respondWith(y(e));return}e.mode==="navigate"&&e.destination==="document"&&t.respondWith(A(e))}}),a.addEventListener("push",t=>{t.waitUntil(Promise.resolve())}),a.addEventListener("notificationclick",t=>{t.notification.close(),t.waitUntil((async()=>{const e=t.notification.data?.url??"/desktop-mode/",c=(await a.clients.matchAll({type:"window",includeUncontrolled:!0})).find(n=>n.url.includes("/desktop-mode/"));if(c){typeof c.focus=="function"&&await c.focus();return}a.clients.openWindow&&await a.clients.openWindow(e)})())});async function f(){try{const t=await caches.open(i),e=w();await t.addAll(p.map(s=>e+s))}catch{}}function w(){return a.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 k(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 n=await(await caches.open(i)).match(t,{ignoreSearch:!0});return n||new Response("",{status:504})}}async function y(t){const e=await caches.open(l),s=await e.match(t),c=fetch(t).then(r=>(r&&r.status===200&&e.put(t,r.clone()).catch(()=>{}),r)).catch(()=>{});if(s)return s;const n=await c;if(n)return n;const d=await(await caches.open(i)).match(t,{ignoreSearch:!0});return d||new Response("",{status:504})}async function A(t){try{return await fetch(t)}catch{const s=await(await caches.open(i)).match(u);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"}})}}})(); |