0
mirror of https://github.com/torvalds/GuitarPedal.git synced 2026-06-07 04:55:36 +00:00
Files
torvalds-GuitarPedal/Software/WebMIDI/service-worker.js
Linus Torvalds d08bd100aa WebMIDI: attempt to fix up MIDI access permission issues
It looks like the device auto-connecting to the MIDI device ends up
sometimes causing permission errors, and then it just gives up and
nothing works subsequently.

It worked when I tested it originally, but that was probably because
then it went through the whole "Do you allow access" dance.

So add an explicit reconnect to the MIDI device.

Also, try to work around the progressive web app just refusing to update
while being in use, and continuing to use stale state.  Which made this
all rather more inconvenient to debug, since the new improved debugging
output didn't actually end up triggering.

Let's see if we have better luck now.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2026-06-01 15:19:13 -07:00

51 lines
1.0 KiB
JavaScript

const CACHE_NAME = 'rp2350-pedal-cache-v4';
const urlsToCache = [
'./',
'./index.html',
'./style.css',
'./app.js',
'./effects.js',
'./manifest.json',
'./icon-192.png',
'./icon-512.png'
];
self.addEventListener('install', event => {
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME)
.then(cache => {
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request)
.then(response => {
// Cache hit - return response
if (response) {
return response;
}
return fetch(event.request);
}
)
);
});
self.addEventListener('activate', event => {
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(cacheName => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});