summaryrefslogtreecommitdiff
path: root/src/client/sw.ts
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2020-12-26 14:11:08 +0900
committersyuilo <syuilotan@yahoo.co.jp>2020-12-26 14:11:08 +0900
commitec4d5857d80938758ce64930159be2c941d4e30f (patch)
treebfa24ed39ef9b90e290a504ca5ed2ee00ef280c7 /src/client/sw.ts
parentAdd note (diff)
downloadmisskey-ec4d5857d80938758ce64930159be2c941d4e30f.tar.gz
misskey-ec4d5857d80938758ce64930159be2c941d4e30f.tar.bz2
misskey-ec4d5857d80938758ce64930159be2c941d4e30f.zip
Fix service worker generation
Diffstat (limited to 'src/client/sw.ts')
-rw-r--r--src/client/sw.ts67
1 files changed, 0 insertions, 67 deletions
diff --git a/src/client/sw.ts b/src/client/sw.ts
deleted file mode 100644
index 01ed216029..0000000000
--- a/src/client/sw.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-/**
- * Service Worker
- */
-declare var self: ServiceWorkerGlobalScope;
-
-import composeNotification from '@/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(
- caches.open(cacheName)
- .then(cache => {
- return cache.addAll([
- `/?v=${version}`
- ]);
- })
- .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(`/?v=${version}`);
- })
- );
-});
-
-// プッシュ通知を受け取ったとき
-self.addEventListener('push', ev => {
- // クライアント取得
- ev.waitUntil(self.clients.matchAll({
- includeUncontrolled: true
- }).then(async clients => {
- // クライアントがあったらストリームに接続しているということなので通知しない
- if (clients.length != 0) return;
-
- const { type, body } = ev.data.json();
-
- return self.registration.showNotification(...(await composeNotification(type, body)));
- }));
-});