From dae3c49aec5a0d3920848c3b966813fff3c6472c Mon Sep 17 00:00:00 2001 From: Bharat Sinha Date: Thu, 12 Jul 2018 08:31:41 +0530 Subject: [PATCH] push --- .DS_Store | Bin 0 -> 6148 bytes app/index.html | 6 +++--- app/my-sw-new.js | 38 ++++++++++++++++++++++++++++++++++++++ app/static/.DS_Store | Bin 0 -> 6148 bytes app/static/js/main.js | 20 ++++++++++---------- 5 files changed, 51 insertions(+), 13 deletions(-) create mode 100644 .DS_Store create mode 100644 app/my-sw-new.js create mode 100644 app/static/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6d46a9b5266cdd7d50fee07728fca800a960e282 GIT binary patch literal 6148 zcmeHK%}T>S5Z<*_w-vDm!5;VGt%v@o#e)!HJ$Mr$dQfQ-T5O;urAZAMD|rolBcH(6 zab|ZT7JKj{VrO9Yo7tJ!&3uskVT^Hm+HWvcVT=iAh#Zv#g2M}4D<&9`;~df08-*TN zZ{FDW{yN~d7nsY&Z0sdpzklRMalQV|R|>_|wRIuNqP$tYafV^y#BMx|Yq|fAhlw3dgMOsuakN8-k|=d6)iiA$ z?$>0q)tuF2+HTita<6qTo0Y`QZsX{*clYp^KFywAG`}3^SF&X=hgVQcdH2pF7=^(t zjO5XI6d^G{3=jjvz)~?_jsdZ;R8>>4!~iky69#a9kkAk~lQ9#GH z1fn!(8O$_-2ZZZXK%L6X6NBq?7?&o_GMH)9>5QwDVIH$`{&?YPbr_c_oN-Gd^~3-% zFwa0in-x6&PvDnX_{g76A&VFw2L2fXyx4I%HWX#f)^FwESu3ISprK$~h6)JibC&=x ia385Er}j(KAWelcome 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 0000000000000000000000000000000000000000..a4a7b7592ef5bc472bcea4a4d45020c16c81741f GIT binary patch literal 6148 zcmeHK%}&BV5Z)Ek1!Lr3BFDXW;{YgfGHEIvyqVPKK@GG*qzSf!78}KyzJ|V$PvGk~ zv%57CIe0QgW|G}+W@l!%^CjIM#u&G!{RU$d#+ZPH$Wd7!IK0rcVuBGl&Jm5hQRsp7 z=8cW-uLFL2f!(l(MPBmt`$v8h*X!?mrBGa5TNk1%%A4hDXBZ|~WliBh*xoz0r< zR!ufr&9o+G?RLE;_xBFcv?O+R8;2*oyNAcwQ~La(`Q<>rk}ZQdynQru?7+j~rxHNH=!Azr0XI!le^O%+M#|u}h!?;x8j9VJ1CkBXt zc?JsFtl;^748P36NB(>YS;PP_@Xr|F#g5alp(t~ { }; 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 = () => {