A music player that connects to your cloud/distributed storage.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Service worker adjustments for native app

+39 -8
+18 -5
src/Javascript/Workers/service.js
··· 18 18 ] 19 19 20 20 21 + const isNativeWrapper = location.host === "localhost:44999" || location.host === "127.0.0.1:44999" 22 + 23 + 21 24 22 25 // 📣 23 26 ··· 33 36 34 37 35 38 self.addEventListener("install", event => { 39 + if (isNativeWrapper) { 40 + return self.skipWaiting() 41 + } 42 + 36 43 const href = self.location.href.replace("service-worker.js", "") 37 44 const promise = fetch("tree.json") 38 45 .then(response => response.json()) ··· 49 56 self.addEventListener("fetch", event => { 50 57 const isInternal = 51 58 !!event.request.url.match(new RegExp("^" + self.location.origin)) 52 - 53 - // const isOffline = 54 - // !self.navigator.onLine 55 59 56 60 // When doing a request with basic authentication in the url, put it in the headers instead 57 61 if (event.request.url.includes("service_worker_authentication=")) { ··· 81 85 "Bearer " + token 82 86 ) 83 87 84 - // Use cache if internal request 88 + // Use cache if internal request and not using native app 85 89 } else if (isInternal) { 86 - event.respondWith( cacheThenNetwork(event) ) 90 + event.respondWith( 91 + isNativeWrapper 92 + ? cacheThenNetwork(event) 93 + : network(event) 94 + ) 87 95 88 96 } 89 97 }) ··· 97 105 .open(KEY) 98 106 .then(cache => cache.match(url)) 99 107 .then(match => match || fetch(url)) 108 + } 109 + 110 + 111 + function network(event) { 112 + return fetch(event.request.url) 100 113 } 101 114 102 115
+21 -3
src/Javascript/index.js
··· 20 20 21 21 22 22 23 + // 🌸 24 + 25 + 26 + const isNativeWrapper = location.host === "localhost:44999" || location.host === "127.0.0.1:44999" 27 + 28 + 29 + 23 30 // 🔐 24 31 25 32 ··· 38 45 } else if ("serviceWorker" in navigator) { 39 46 window.addEventListener("load", () => { 40 47 navigator.serviceWorker 41 - .register("service-worker.js") 48 + .getRegistrations() 49 + .then(registrations => { 50 + // native app should not have to install a new service worker 51 + if (isNativeWrapper) { 52 + return Promise.all(registrations.map(r => r.unregister())) 53 + } 54 + 55 + return Promise.resolve([]) 56 + }) 57 + .then(_ => navigator.serviceWorker.register("service-worker.js")) 42 58 .catch(err => { 43 59 const isFirefox = navigator.userAgent.toLowerCase().includes("firefox") 44 60 ··· 900 916 }) 901 917 902 918 // Check for service worker updates and every hour after that 903 - reg.update() 904 - setInterval(() => reg.update(), 1 * 1000 * 60 * 60) 919 + if (!isNativeWrapper) { 920 + reg.update() 921 + setInterval(() => reg.update(), 1 * 1000 * 60 * 60) 922 + } 905 923 } 906 924 907 925