forked from external-repos/squoosh
Add share target (#469)
* Quick test * More testing * More testing * Removing transfer for now * Changing name so it's easier to tell them apart when installed * Disable minification to ease debugging * Adding navigate lock * lol oops * Add minifying back * Removing minification again, for debugging * Removing broadcast channel bits, to simplify the code * Revert "Removing broadcast channel bits, to simplify the code" This reverts commit 0b2a3ecf2986aae0dd65fdd1ddda2bd9e4e1eac7. * I think this fixes it * Refactor * Suppress flash of home screen during share target * Almost ready, so switching to real name * Removing log * Ahh yes the trailing comma thing * Removing use of BroadcastChannel * Reducing ternary
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import {
|
||||
cacheOrNetworkAndCache, cleanupCache, cacheOrNetwork, cacheBasics, cacheAdditionalProcessors,
|
||||
serveShareTarget,
|
||||
} from './util';
|
||||
import { get } from 'idb-keyval';
|
||||
|
||||
@@ -40,14 +41,23 @@ self.addEventListener('activate', (event) => {
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
// We only care about GET.
|
||||
if (event.request.method !== 'GET') return;
|
||||
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// Don't care about other-origin URLs
|
||||
if (url.origin !== location.origin) return;
|
||||
|
||||
if (
|
||||
url.pathname === '/' &&
|
||||
url.searchParams.has('share-target') &&
|
||||
event.request.method === 'POST'
|
||||
) {
|
||||
serveShareTarget(event);
|
||||
return;
|
||||
}
|
||||
|
||||
// We only care about GET from here on in.
|
||||
if (event.request.method !== 'GET') return;
|
||||
|
||||
if (url.pathname.startsWith('/demo-') || url.pathname.startsWith('/wc-polyfill')) {
|
||||
cacheOrNetworkAndCache(event, dynamicCache);
|
||||
cleanupCache(event, dynamicCache, BUILD_ASSETS);
|
||||
|
||||
Reference in New Issue
Block a user