| 1 |
(function(){"use strict";const a=globalThis,r="0.8.0-pwa-5",o=`desktop-mode-static-${r}`,h=`desktop-mode-runtime-${r}`,l="/desktop-mode/?offline=1",d=["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(u()),a.skipWaiting()}),a.addEventListener("activate",t=>{t.waitUntil((async()=>{const e=await caches.keys();await Promise.all(e.filter(s=>!s.endsWith(r)).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/"),i=s.pathname.includes("/wp-content/plugins/desktop-mode/");if(!(!c&&!n&&!i)){if(i&&w(s.pathname)){t.respondWith(m(e));return}if(i&&f(s.pathname)){t.respondWith(g(e));return}e.mode==="navigate"&&e.destination==="document"&&t.respondWith(k(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 u(){try{const t=await caches.open(o),e=p();await t.addAll(d.map(s=>e+s))}catch{}}function p(){return a.location.origin+"/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 e=await caches.open(h);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(o)).match(t,{ignoreSearch:!0});return n||new Response("",{status:504})}}async function g(t){const e=await caches.open(h);let s=await e.match(t);s||(s=await(await caches.open(o)).match(t,{ignoreSearch:!0}));const c=fetch(t).then(i=>(i&&i.status===200&&e.put(t,i.clone()).catch(()=>{}),i)).catch(()=>{});if(s)return s;const n=await c;return n||new Response("",{status:504})}async function k(t){try{return await fetch(t)}catch{const s=await(await caches.open(o)).match(l);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"}})}}})(); |