diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..6d46a9b Binary files /dev/null and b/.DS_Store differ diff --git a/app/index.html b/app/index.html index 9ecd9ce..f880609 100644 --- a/app/index.html +++ b/app/index.html @@ -165,7 +165,7 @@

Welcome

var registerServiceWorker = () => { var success = (reg) => { console.log('Service Worker Registered Successfully', reg); - return reg.pushManager.getSubscription() + // return reg.pushManager.getSubscription() }; let subscribe = (subscribeState) => { if (subscribeState === null) { @@ -179,9 +179,9 @@

Welcome

console.log('Service worker registeration failed', err); }; if('serviceWorker' in navigator){ - navigator.serviceWorker.register('/sw-wb.js') + navigator.serviceWorker.register('/my-sw-new.js') .then(success) - .then(subscribe) + // .then(subscribe) .catch(error); } }; diff --git a/app/my-sw-new.js b/app/my-sw-new.js new file mode 100644 index 0000000..000a39a --- /dev/null +++ b/app/my-sw-new.js @@ -0,0 +1,38 @@ +const CACHE_NAME = 'cache_v1'; + +const PRECACHE_LIST = [ + '/static/js/material.min.js', + '/static/css/material.min.css', + '/index.html', + '/', +]; + +self.addEventListener('install', (e) => { + e.waitUntil( + caches + .open(CACHE_NAME) + .then(cache => { + return cache.addAll(PRECACHE_LIST); + }) + ); +}); + +self.addEventListener('fetch', e => { + e.respondWith( + caches.match(e.request) + .then(response => { + if (response) { + return response; + } + + let requestClone = e.request.clone(); + return fetch(requestClone) + .then((res) => { + if (!res || res.status !== 200 || res.type !== 'basic') { + return res; + } + }) + + }) + ); +}); \ No newline at end of file diff --git a/app/static/.DS_Store b/app/static/.DS_Store new file mode 100644 index 0000000..a4a7b75 Binary files /dev/null and b/app/static/.DS_Store differ diff --git a/app/static/js/main.js b/app/static/js/main.js index 1c6a5ea..d7311e4 100644 --- a/app/static/js/main.js +++ b/app/static/js/main.js @@ -157,16 +157,16 @@ const changeButtonStatus = (status) => { }; const subscribeForPush = () => { - navigator.serviceWorker.ready - .then((reg) => { - console.log('here', reg); - reg.pushManager.subscribe({ userVisibleOnly: true }) - .then(subscribe => { - console.log(subscribe.endpoint, 'subscribed'); - storeSubscriptionDetails(subscribe.endpoint); - }) - .catch(err => console.error(err)); - }) + // navigator.serviceWorker.ready + // .then((reg) => { + // console.log('here', reg); + // reg.pushManager.subscribe({ userVisibleOnly: true }) + // .then(subscribe => { + // console.log(subscribe.endpoint, 'subscribed'); + // storeSubscriptionDetails(subscribe.endpoint); + // }) + // .catch(err => console.error(err)); + // }) }; const subscribeToNotification = () => {