Skip to content

Commit

Permalink
improved SW
Browse files Browse the repository at this point in the history
  • Loading branch information
Specy committed Apr 8, 2024
1 parent a3b28b4 commit b5c5de9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 15 deletions.
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"react": "^18.2.0",
"react-colorful": "^5.6.1",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0",
"react-icons": "^5.0.1",
"semver": "^7.5.4",
"workbox-core": "^7.0.0",
"workbox-precaching": "^7.0.0",
Expand Down
10 changes: 5 additions & 5 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"file_handlers": [
{
"action": "/",
"action": ".",
"name": "Import file in sky music",
"accept": {
"application/json": [
Expand All @@ -33,17 +33,17 @@
},
"icons": [
{
"src": "/favicon.ico",
"src": "favicon.ico",
"sizes": "48x48",
"type": "image/x-icon"
},
{
"src": "/logo192.png",
"src": "logo192.png",
"type": "image/png",
"sizes": "192x192"
},
{
"src": "/logo512.png",
"src": "logo512.png",
"type": "image/png",
"sizes": "512x512"
}
Expand Down Expand Up @@ -72,4 +72,4 @@
"orientation": "landscape",
"theme_color": "#63aea7",
"background_color": "#495466"
}
}
2 changes: 1 addition & 1 deletion public/service-worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/lib/updates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const updates: Update[] = [
{
version: '3.3.0',
title: "Audio/Video transcription, reverb",
date: new Date('2024-04-02'),
date: new Date('2024-04-08'),
changes: [
"Added tool in the composer to convert audio/video to a sheet",
"Reverb now can be set for each instrument",
Expand Down
33 changes: 31 additions & 2 deletions src/service-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
// You can also remove this file if you'd prefer not to use a
// service worker, and the Workbox build step will be skipped.
import {clientsClaim, setCacheNameDetails} from 'workbox-core';
import {precacheAndRoute} from 'workbox-precaching';
import {registerRoute} from 'workbox-routing';
import {CacheFirst, NetworkFirst} from 'workbox-strategies';

Expand Down Expand Up @@ -38,6 +37,14 @@ const FILTERED_MANIFEST = PRECACHE_MANIFEST.filter(e => !(
return e
})
console.log("Precached files:", FILTERED_MANIFEST)

function forbiddenCachedItems(url: URL) {
if (url.pathname.includes("service-worker")
|| url.pathname.includes("manifestData")
|| url.pathname.endsWith(".json")) return true

}

if (IS_TAURI) {

} else {
Expand All @@ -46,11 +53,33 @@ if (IS_TAURI) {
//precacheAndRoute(FILTERED_MANIFEST);
console.log("registering routes")
registerRoute(
new RegExp('/*'),
({url}) => {
if (forbiddenCachedItems(new URL(url))) {
console.log("forbidden", url.pathname)
return false
}
console.log("allowed", url.pathname)
return true
},
new NetworkFirst({
cacheName: RUNTIME_CACHE
})
);
registerRoute(
({url}) => {
if (forbiddenCachedItems(new URL(url))){
return false
}
if(url.pathname.endsWith(".mp3") || url.pathname.endsWith(".wav")){
console.log("runtime cache audio", url.pathname)
return true
}
return false
},
new CacheFirst({
cacheName: RUNTIME_CACHE
})
)
}

// This allows the web app to trigger skipWaiting via
Expand Down

0 comments on commit b5c5de9

Please sign in to comment.