Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PWA #531

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

PWA #531

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<link rel="apple-touch-icon" href="meta/apple-touch-icon.png">
<link rel="apple-touch-startup-image" href="meta/apple-touch-startup-image-640x1096.png" media="(device-width: 320px) and (device-height: 568px) and (-webkit-device-pixel-ratio: 2)"> <!-- iPhone 5+ -->
<link rel="apple-touch-startup-image" href="meta/apple-touch-startup-image-640x920.png" media="(device-width: 320px) and (device-height: 480px) and (-webkit-device-pixel-ratio: 2)"> <!-- iPhone, retina -->
<link rel="manifest" href="/manifest.json">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">

Expand Down
3 changes: 3 additions & 0 deletions js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
window.requestAnimationFrame(function () {
new GameManager(4, KeyboardInputManager, HTMLActuator, LocalStorageManager);
});
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("../sw.js");
}
23 changes: 23 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "2048",
"short_name": "2048",
"description": "2048 game",
"theme_color": "#FAF8EF",
"background_color": "#FAF8EF",
"display": "standalone",
"scope": "/",
"orientation": "portrait",
"start_url": "/",
"icons": [
{
"src": "/favicon.svg",
"type": "image/svg+xml",
"sizes": "32x32"
},
{
"src": "/meta/apple-touch-icon.png",
"type": "image/png",
"sizes": "152x152"
}
]
}
46 changes: 46 additions & 0 deletions sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// This code executes in its own worker or thread
const urlsToCache = [
"index.html",
"style/main.css",
"favicon.svg",
"favicon.ico",
"/js/animframe_polyfill.js",
"/js/application.js",
"/js/bind_polyfill.js",
"/js/classlist_polyfill.js",
"/js/dom.js",
"/js/game_manager.js",
"/js/grid.js",
"/js/html_actuator.js",
"/js/in-page.js",
"/js/js.js",
"/js/keyboard_input_manager.js",
"/js/local_storage_manager.js",
"/js/tile.js",
"/meta/apple-touch-icon.png",
"/meta/apple-touch-startup-image-640x920.png",
"/mata/apple-touch-startup-image-640x1096.png",
"/style/fonts/ClearSans-Bold-webfont.woff",
"/style/fonts/ClearSans-Regular-webfont.woff",
"/style/fonts/clear-sans.css",
];

self.addEventListener("install", (event) => {
event.waitUntil(async () => {
const cache = await caches.open("pwa-assets");
return cache.addAll(urlsToCache);
});
});

self.addEventListener("activate", (event) => {
console.log("Service worker activated");
});

self.addEventListener("fetch", (event) => {
event.respondWith(
caches.match(event.request).then((cachedResponse) => {
// It can update the cache to serve updated content on the next request
return cachedResponse || fetch(event.request);
})
);
});