123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- const CACHE_NAME = 'MeeChat_v1.3.4';
- let urlsToCache = ["/dist/css/chunk-17f20f02.0b938788.css","/dist/css/chunk-21bd4ca5.19ff19e6.css","/dist/css/chunk-23212ac5.7b7b6769.css","/dist/css/chunk-3a2cfe68.4d1c99dd.css","/dist/css/chunk-3ab2e3e3.621d2337.css","/dist/css/chunk-3ae6835b.601b91da.css","/dist/css/chunk-484a20ba.6c4d2f2f.css","/dist/css/chunk-4be0e358.e275999c.css","/dist/css/chunk-4eaa1259.4462b17e.css","/dist/css/chunk-55ee6bb8.f31f92a7.css","/dist/css/chunk-579c6ae2.f3c7912e.css","/dist/css/chunk-5b86aac9.a00b706f.css","/dist/css/chunk-5c065784.1e2497e0.css","/dist/css/chunk-650cd7d0.f8b796f1.css","/dist/css/chunk-652c94c5.9dccaae5.css","/dist/css/chunk-6aeec874.735872c4.css","/dist/css/chunk-6cae8a9b.a8887c6a.css","/dist/css/chunk-74d0d27c.cad96ca9.css","/dist/css/chunk-7fdb0984.f80ccfd7.css","/dist/css/chunk-a6830cb4.feb38348.css","/dist/css/chunk-b5c34688.af0499b2.css","/dist/css/chunk-ba45f5e6.4ad04c39.css","/dist/css/chunk-common.15737a0f.css","/dist/css/chunk-d7186f64.9ac0224d.css","/dist/css/chunk-dcb2943e.fd3b7528.css","/dist/css/chunk-eab6c874.835e2cbb.css","/dist/css/chunk-ed0382aa.4b654aae.css","/dist/css/chunk-fbfb9796.8e1bb200.css","/dist/css/chunk-vendors.be5bb01d.css","/dist/css/h5.906f4d0f.css","/dist/css/mini.7e846a75.css","/dist/css/pc.bdb56b85.css","/dist/favicon.ico","/dist/fonts/element-icons.535877f5.woff","/dist/fonts/element-icons.732389de.ttf","/h5.html","/dist/img/bg.261295d3.jpg","/dist/img/bg.71de928a.jpg","/dist/img/icon-eth.f49c5cf6.png","/dist/img/icon-meetone.f0168873.png","/dist/img/icon-tele.0c036f6a.png","/dist/img/icon-tele.88177f4a.png","/dist/img/icons/meechat.png","/dist/img/icons/meechat_icon.png","/dist/img/icons/safari-pinned-tab.svg","/dist/img/loading.b4490fa6.gif","/dist/img/login-logo.6f40e8ff.png","/dist/img/meetone-icon.f0168873.jpg","/dist/img/user-ethereum-icon.fdf8b24e.png","/dist/img/user-tron-icon.92300839.png","/index.html","/dist/js/chunk-17f20f02.028ca99e.js","/dist/js/chunk-21bd4ca5.5edf431f.js","/dist/js/chunk-23212ac5.495e6717.js","/dist/js/chunk-335f5c5d.ae359ac3.js","/dist/js/chunk-3a2cfe68.8856c27f.js","/dist/js/chunk-3ab2e3e3.7bdfd765.js","/dist/js/chunk-3ae6835b.65cce310.js","/dist/js/chunk-484a20ba.f98c653b.js","/dist/js/chunk-4be0e358.0134820c.js","/dist/js/chunk-4eaa1259.f6897660.js","/dist/js/chunk-55ee6bb8.642b9d3f.js","/dist/js/chunk-579c6ae2.801520b4.js","/dist/js/chunk-5b86aac9.6cd73d35.js","/dist/js/chunk-5c065784.1ecea1c6.js","/dist/js/chunk-650cd7d0.4edc6889.js","/dist/js/chunk-652c94c5.a2d760b7.js","/dist/js/chunk-6aeec874.50a341d2.js","/dist/js/chunk-6cae8a9b.5515e975.js","/dist/js/chunk-74d0d27c.e822f118.js","/dist/js/chunk-7fdb0984.21c4c9c5.js","/dist/js/chunk-a6830cb4.1ed61dfc.js","/dist/js/chunk-b5c34688.368c663d.js","/dist/js/chunk-ba45f5e6.1718c2d7.js","/dist/js/chunk-common.b014f402.js","/dist/js/chunk-d7186f64.9705837b.js","/dist/js/chunk-dcb2943e.3636e365.js","/dist/js/chunk-eab6c874.9277e1e9.js","/dist/js/chunk-ed0382aa.62c0e7d4.js","/dist/js/chunk-fbfb9796.bc1a3bfd.js","/dist/js/chunk-vendors.23fde345.js","/dist/js/h5.f7c1374b.js","/dist/js/mini.69d406c0.js","/dist/js/pc.045b9707.js","/manifest_h5.json","/manifest_pc.json","/mini.html","/pc.html","/dist/robots.txt","/dist/sw.js"];
- // let networkFirstList = ['', 'h5.html', 'mini.html'];
- let networkFirstList = [];
- self.addEventListener('install', function (event) {
- self.skipWaiting();
- console.log('[ServiceWorker] install')
- event.waitUntil(
- caches.open(CACHE_NAME).then(function(caches){
- console.log('open cache:' + CACHE_NAME);
- let allList = urlsToCache.concat(networkFirstList)
- return caches.addAll(allList);
- })
- )
- })
- self.addEventListener('activate', function (event) {
- console.log('[ServiceWorker] activate')
- // 只保留白名单的版本
- const cacheWhitelist = [CACHE_NAME];
- event.waitUntil(
- caches.keys().then(function(cacheNames) {
- return Promise.all(
- cacheNames.map(function(cacheName) {
- console.log('遍历缓存:' + cacheName)
- if (cacheWhitelist.indexOf(cacheName) === -1) {
- console.log('删除缓存:' + cacheName)
- return caches.delete(cacheName)
- }
- })
- )
- })
- )
- })
- self.addEventListener('fetch', function (event) {
- // console.log('[ServiceWorker] Fetch', event.request.url)
- let url = event.request.url.replace(location.origin, '')
- url = url.replace('https:', '')
- let pos = url.indexOf('#')
- if (pos > 0) {
- url = url.substr(0, pos)
- }
- if (urlsToCache.indexOf(url) !== -1) {
- return _cacheFirst(event)
- } else {
- return _networkFirst(event)
- }
- })
- function _cacheFirst(event) {
- event.respondWith(
- caches.match(event.request).then(function (response) {
- // Cache hit - return response
- if (response) {
- return response;
- }
- return fetch(event.request);
- })
- );
- }
- function _networkFirst(event) {
- event.respondWith(
- fetch(event.request).then((response) => {
- // console.log('[ServiceWorker] network first, request: ', event.request.url);
- return response
- }).catch (() => {
- caches.match(event.request).then(function (response) {
- // Cache hit - return response
- if (response) {
- // console.log('[ServiceWorker] cache first, From cache:', event.request.url)
- return response;
- }
- // console.log('[ServiceWorker] cache first, From network:', event.request.url)
- return fetch(event.request);
- })
- })
- );
- }
- self.addEventListener('error', function (event) {
- console.log('[ServiceWorker] error', event)
- })
- self.addEventListener('push', function (event) {
- console.log('[Service Worker] 收到通知', event);
- function decodeUnicode (str) {
- str = str.replace(/\\/g, '%')
- str = unescape(str)
- str = str.replace(/%/g, '\\')
- str = str.replace(/\\/g, '')
- return str
- }
- let data = JSON.parse(event.data.text())
- const title = decodeUnicode(data.title)
- const options = {
- body: decodeUnicode(data.content),
- icon: 'img/icons/meechat.png',
- tag: data.tag,
- data: data.data,
- }
- event.waitUntil(self.registration.showNotification(title, options))
- })
- // 点击跳转
- self.addEventListener('notificationclick', function (event) {
- console.log('[Service Worker] 点击通知', event);
- let data = event.notification.data
- let url = data && data.url || 'https://mee.chat/'
- event.notification.close()
- event.waitUntil(
- clients.openWindow(url)
- )
- })
|