diff --git a/assets/icons/512.png b/assets/icons/512.png new file mode 100644 index 000000000..e2e6ad3ca --- /dev/null +++ b/assets/icons/512.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad94b8da69e291ef58e8dcf88053e05387bfb1ac74eab08598359206cd0eb169 +size 10231 diff --git a/assets/icons/icon.svg b/assets/icons/icon.svg new file mode 100644 index 000000000..46238e6cd --- /dev/null +++ b/assets/icons/icon.svg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:630eac0d1e1f736fb99a05567c19b0014521f0986334bfa14c6c87eb20912139 +size 5729 diff --git a/src/client/app/boot.js b/src/client/app/boot.js index 583cc4fc8..c244050a5 100644 --- a/src/client/app/boot.js +++ b/src/client/app/boot.js @@ -98,15 +98,10 @@ // If mobile, insert the viewport meta tag if (isMobile) { - const meta = document.createElement('meta'); - meta.setAttribute('name', 'viewport'); - meta.setAttribute('content', - 'width=device-width,' + - 'initial-scale=1,' + - 'minimum-scale=1,' + - 'maximum-scale=1,' + - 'user-scalable=no'); - head.appendChild(meta); + const viewport = document.getElementsByName("viewport").item(0); + viewport.setAttribute('content', + `${viewport.getAttribute('content')},minimum-scale=1,maximum-scale=1,user-scalable=no`); + head.appendChild(viewport); } // Switch desktop or mobile version diff --git a/src/client/app/sw.js b/src/client/app/sw.js index 92f2ac828..d080130e3 100644 --- a/src/client/app/sw.js +++ b/src/client/app/sw.js @@ -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("/"); + }) + ); }); // プッシュ通知を受け取ったとき diff --git a/src/server/web/views/base.pug b/src/server/web/views/base.pug index 16bea853e..97c7a87e1 100644 --- a/src/server/web/views/base.pug +++ b/src/server/web/views/base.pug @@ -12,7 +12,9 @@ html meta(name='referrer' content='origin') meta(name='theme-color' content='#105779') meta(property='og:site_name' content= instanceName || 'Misskey') + meta(name='viewport' content='width=device-width, initial-scale=1') link(rel='icon' href= icon || '/favicon.ico') + link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png') link(rel='manifest' href='/manifest.json') title