mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-04 13:05:57 +02:00
PWA Fix (#5432)
* PWA Fix * SWが/api/へのリクエストに関与しないように * fix semicolon * Update base.pug * Update base.pug
This commit is contained in:
@@ -4,13 +4,53 @@
|
||||
|
||||
import composeNotification from './common/scripts/compose-notification';
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const version = _VERSION_;
|
||||
const cacheName = `mk-cache-${version}`;
|
||||
|
||||
const apiUrl = `${location.origin}/api/`;
|
||||
|
||||
// インストールされたとき
|
||||
self.addEventListener('install', ev => {
|
||||
console.info('installed');
|
||||
|
||||
ev.waitUntil(Promise.all([
|
||||
self.skipWaiting(), // Force activate
|
||||
]));
|
||||
ev.waitUntil(
|
||||
caches.open(cacheName)
|
||||
.then(cache => {
|
||||
return cache.addAll([
|
||||
"/",
|
||||
`/assets/desktop.${version}.js`,
|
||||
`/assets/mobile.${version}.js`,
|
||||
"/assets/error.jpg"
|
||||
]);
|
||||
})
|
||||
.then(() => self.skipWaiting())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('activate', ev => {
|
||||
ev.waitUntil(
|
||||
caches.keys()
|
||||
.then(cacheNames => Promise.all(
|
||||
cacheNames
|
||||
.filter((v) => v !== cacheName)
|
||||
.map(name => caches.delete(name))
|
||||
))
|
||||
.then(() => self.clients.claim())
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', ev => {
|
||||
if (ev.request.method !== 'GET' || ev.request.url.startsWith(apiUrl)) return;
|
||||
ev.respondWith(
|
||||
caches.match(ev.request)
|
||||
.then(response => {
|
||||
return response || fetch(ev.request);
|
||||
})
|
||||
.catch(() => {
|
||||
return caches.match("/");
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
// プッシュ通知を受け取ったとき
|
||||
|
||||
Reference in New Issue
Block a user