aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-08-24 22:08:37 +0300
committerGitHub <noreply@github.com>2020-08-24 22:08:37 +0300
commit6a9970e0994b3b9230a5ead21f0a2dd96c81c40c (patch)
treee30b5f131ac652a5783983aa576a7a27b24a8440
parent89f038c7a0ccf6de94516cba8499a0bc69f8dae1 (diff)
parent18f71aff2c4161792aa2857d0e1b18cf402e55f6 (diff)
downloadwhich-ui-6a9970e0994b3b9230a5ead21f0a2dd96c81c40c.tar.gz
Merge pull request #94 from which-ecosystem/pwa
Configure PWA
-rw-r--r--package-lock.json2
-rw-r--r--package.json2
-rw-r--r--public/index.html13
-rw-r--r--public/manifest.json15
-rw-r--r--public/service-worker.js53
-rw-r--r--public/which-logo-144.pngbin0 -> 5497 bytes
6 files changed, 82 insertions, 3 deletions
diff --git a/package-lock.json b/package-lock.json
index 9b4ef60..4f71e0b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "which",
- "version": "1.2.4",
+ "version": "1.2.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index abfcc76..22c87ff 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "which",
- "version": "1.2.4",
+ "version": "1.2.5",
"homepage": "https://which-ecosystem.github.io/",
"dependencies": {
"@material-ui/core": "^4.10.1",
diff --git a/public/index.html b/public/index.html
index 090b0d5..c921a87 100644
--- a/public/index.html
+++ b/public/index.html
@@ -2,8 +2,12 @@
<html lang="en">
<head>
<meta charset="utf-8" />
- <link rel="icon" type="image/png" sizes="16x16" href="./which-logo-64.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
+ <meta name="theme-color" content="#00796b" />
+ <meta name="description" content="Social webapp based on choosing between two options." />
+ <link rel="icon" type="image/png" href="./which-logo-64.png" />
+ <link rel="apple-touch-icon" href="./which-logo-144.png" />
+ <link rel="manifest" href="./manifest.json" />
<title>Which</title>
<!-- Start Single Page Apps for GitHub Pages -->
<script type="text/javascript">
@@ -40,5 +44,12 @@
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
+ <script>
+ if ('serviceWorker' in navigator) {
+ window.addEventListener('load', () => {
+ navigator.serviceWorker.register('./service-worker.js')
+ })
+ }
+ </script>
</body>
</html>
diff --git a/public/manifest.json b/public/manifest.json
new file mode 100644
index 0000000..aed7ee3
--- /dev/null
+++ b/public/manifest.json
@@ -0,0 +1,15 @@
+{
+ "short_name": "Which",
+ "name": "Which",
+ "icons": [
+ {
+ "src": "which-logo-144.png",
+ "type": "image/png",
+ "sizes": "144x144",
+ "purpose": "maskable"
+ }
+ ],
+ "display": "standalone",
+ "theme_color": "#00796b",
+ "background_color": "#ffffff"
+}
diff --git a/public/service-worker.js b/public/service-worker.js
new file mode 100644
index 0000000..ddab607
--- /dev/null
+++ b/public/service-worker.js
@@ -0,0 +1,53 @@
+const CACHE_NAME = 'v1.2.5'; // Per-version requests cache
+const IMAGES_CACHE_NAME = 'images' // Long-term images cache
+
+const isS3Url = url => url.includes('amazonaws.com');
+
+this.addEventListener('install', event => {
+ event.waitUntil(
+ caches.open(CACHE_NAME)
+ .then(cache => cache.addAll(['index.html']))
+ .catch(e => console.log(e))
+ );
+})
+
+this.addEventListener('fetch', event => {
+ if (isS3Url(event.request.url)) {
+ event.respondWith(
+ caches.open(IMAGES_CACHE_NAME)
+ .then(cache => cache.match(event.request)
+ .then(match => match || fetch(event.request)
+ .then(response => {
+ cache.put(event.request, response.clone());
+ return response;
+ })
+ )
+ .catch(e => console.log(`Error ${e}`))
+ )
+ );
+ } else {
+ event.respondWith(
+ caches.open(CACHE_NAME)
+ .then(cache => fetch(event.request)
+ .then(response => {
+ cache.put(event.request, response.clone());
+ return response;
+ })
+ .catch(() => cache.match(event.request))
+ )
+ );
+ }
+});
+
+this.addEventListener('activate', event => {
+ const cacheWhiteList = [CACHE_NAME];
+ event.waitUntil(
+ caches.keys()
+ .then(keys => Promise.all(
+ keys.map(key => {
+ if (cacheWhiteList.indexOf(key) === -1) return caches.delete(key);
+ })
+ ))
+ );
+});
+
diff --git a/public/which-logo-144.png b/public/which-logo-144.png
new file mode 100644
index 0000000..c51c498
--- /dev/null
+++ b/public/which-logo-144.png
Binary files differ