diff options
Diffstat (limited to 'app/javascript')
-rw-r--r-- | app/javascript/mastodon/service_worker/entry.js | 22 | ||||
-rw-r--r-- | app/javascript/styles/mastodon/accounts.scss | 1 |
2 files changed, 22 insertions, 1 deletions
diff --git a/app/javascript/mastodon/service_worker/entry.js b/app/javascript/mastodon/service_worker/entry.js index eea4cfc3c..ad933b95e 100644 --- a/app/javascript/mastodon/service_worker/entry.js +++ b/app/javascript/mastodon/service_worker/entry.js @@ -1,10 +1,30 @@ import './web_push_notifications'; +function fetchRoot() { + return fetch('/', { credentials: 'include' }); +} + // Cause a new version of a registered Service Worker to replace an existing one // that is already installed, and replace the currently active worker on open pages. self.addEventListener('install', function(event) { - event.waitUntil(self.skipWaiting()); + const promises = Promise.all([caches.open('mastodon-web'), fetchRoot()]); + const asyncAdd = promises.then(([cache, root]) => cache.put('/', root)); + + event.waitUntil(asyncAdd); }); self.addEventListener('activate', function(event) { event.waitUntil(self.clients.claim()); }); +self.addEventListener('fetch', function(event) { + const url = new URL(event.request.url); + + if (url.pathname.startsWith('/web/')) { + event.respondWith(fetchRoot().then(response => { + if (response.ok) { + return response; + } + + throw null; + }).catch(() => caches.match('/'))); + } +}); diff --git a/app/javascript/styles/mastodon/accounts.scss b/app/javascript/styles/mastodon/accounts.scss index 873963c90..dd82ab375 100644 --- a/app/javascript/styles/mastodon/accounts.scss +++ b/app/javascript/styles/mastodon/accounts.scss @@ -440,6 +440,7 @@ text-align: center; padding: 60px 0; padding-top: 55px; + margin: 0 auto; cursor: default; } |