forked from FoundKeyGang/FoundKey
PWA Fix (#5432)
* PWA Fix * SWが/api/へのリクエストに関与しないように * fix semicolon * Update base.pug * Update base.pug
This commit is contained in:
parent
e94dd8a5e8
commit
b040ac6373
5 changed files with 49 additions and 12 deletions
BIN
assets/icons/512.png
Normal file
BIN
assets/icons/512.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
BIN
assets/icons/icon.svg
Normal file
BIN
assets/icons/icon.svg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.6 KiB |
|
@ -98,15 +98,10 @@
|
||||||
|
|
||||||
// If mobile, insert the viewport meta tag
|
// If mobile, insert the viewport meta tag
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
const meta = document.createElement('meta');
|
const viewport = document.getElementsByName("viewport").item(0);
|
||||||
meta.setAttribute('name', 'viewport');
|
viewport.setAttribute('content',
|
||||||
meta.setAttribute('content',
|
`${viewport.getAttribute('content')},minimum-scale=1,maximum-scale=1,user-scalable=no`);
|
||||||
'width=device-width,' +
|
head.appendChild(viewport);
|
||||||
'initial-scale=1,' +
|
|
||||||
'minimum-scale=1,' +
|
|
||||||
'maximum-scale=1,' +
|
|
||||||
'user-scalable=no');
|
|
||||||
head.appendChild(meta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Switch desktop or mobile version
|
// Switch desktop or mobile version
|
||||||
|
|
|
@ -4,13 +4,53 @@
|
||||||
|
|
||||||
import composeNotification from './common/scripts/compose-notification';
|
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 => {
|
self.addEventListener('install', ev => {
|
||||||
console.info('installed');
|
console.info('installed');
|
||||||
|
|
||||||
ev.waitUntil(Promise.all([
|
ev.waitUntil(
|
||||||
self.skipWaiting(), // Force activate
|
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("/");
|
||||||
|
})
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// プッシュ通知を受け取ったとき
|
// プッシュ通知を受け取ったとき
|
||||||
|
|
|
@ -12,7 +12,9 @@ html
|
||||||
meta(name='referrer' content='origin')
|
meta(name='referrer' content='origin')
|
||||||
meta(name='theme-color' content='#105779')
|
meta(name='theme-color' content='#105779')
|
||||||
meta(property='og:site_name' content= instanceName || 'Misskey')
|
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='icon' href= icon || '/favicon.ico')
|
||||||
|
link(rel='apple-touch-icon' href= icon || '/apple-touch-icon.png')
|
||||||
link(rel='manifest' href='/manifest.json')
|
link(rel='manifest' href='/manifest.json')
|
||||||
|
|
||||||
title
|
title
|
||||||
|
|
Loading…
Reference in a new issue