Rework the phone layout and make the game installable
Phones get a one-row status strip, a bottom tab bar (play, speed, goals, deals, NOC, networks) and draggable bottom sheets; in landscape the sheets slide in from the side. Toasts can be tapped away, dialogs become bottom sheets and the title screen keeps its start button in reach. Adds a service worker for offline play and an install button (the browser prompt on Android, instructions on iOS).
This commit is contained in:
parent
cc28dfeb74
commit
5786f76ed9
5 changed files with 188 additions and 12 deletions
32
site/sw.js
Normal file
32
site/sw.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* Series of Tubes service worker: makes the game installable and playable offline.
|
||||
The page always comes from the network when there is one, so a new release shows up on the
|
||||
next visit; everything else is served from the cache and refreshed in the background. */
|
||||
const CACHE = 'sot-__VERSION__';
|
||||
const CORE = ['/', '/index.html', '/site.webmanifest', '/favicon.svg', '/icon-192.png', '/icon-512.png', '/apple-touch-icon.png', '/i18n/it.js?v=__VERSION__'];
|
||||
|
||||
self.addEventListener('install', (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(CORE)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (e) => {
|
||||
e.waitUntil(caches.keys().then((keys) => Promise.all(keys.filter((k) => k.startsWith('sot-') && k !== CACHE).map((k) => caches.delete(k)))).then(() => self.clients.claim()));
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (e) => {
|
||||
const req = e.request;
|
||||
if (req.method !== 'GET') return;
|
||||
const url = new URL(req.url);
|
||||
// The update check must always ask the network.
|
||||
if (url.origin === location.origin && url.pathname === '/version.json') return;
|
||||
if (req.mode === 'navigate') {
|
||||
e.respondWith(fetch(req).then((r) => { const copy = r.clone(); caches.open(CACHE).then((c) => c.put('/', copy)); return r; })
|
||||
.catch(() => caches.match('/').then((r) => r || caches.match('/index.html'))));
|
||||
return;
|
||||
}
|
||||
const local = url.origin === location.origin, fonts = /fonts\.(googleapis|gstatic)\.com$/.test(url.hostname);
|
||||
if (!local && !fonts) return;
|
||||
e.respondWith(caches.open(CACHE).then((c) => c.match(req).then((hit) => {
|
||||
const net = fetch(req).then((r) => { if (r && (r.ok || r.type === 'opaque')) c.put(req, r.clone()); return r; }).catch(() => hit);
|
||||
return hit || net;
|
||||
})));
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue