forked from M-Labs/web2019
parent
2aec9fb4a0
commit
54cb76eece
After Width: | Height: | Size: 48 KiB |
@ -0,0 +1,40 @@ |
||||
(function () { |
||||
|
||||
var swRegistration; |
||||
var newWorker; |
||||
var isRefreshing = false; |
||||
var pathname = window.location.pathname; |
||||
var deferredPrompt; |
||||
|
||||
window.addEventListener('beforeinstallprompt', (e) => { |
||||
console.log('[AS] Before install prompt'); |
||||
// Prevent Chrome 67 and earlier from automatically showing the prompt
|
||||
e.preventDefault(); |
||||
// Stash the event so it can be triggered later.
|
||||
deferredPrompt = e; |
||||
}); |
||||
|
||||
if ('serviceWorker' in navigator) { |
||||
console.info('Service Worker is supported'); |
||||
|
||||
window.addEventListener('load', function () { |
||||
navigator.serviceWorker.register('/sw.js', { |
||||
updateViaCache: 'all', |
||||
}).then(function (registration) { |
||||
swRegistration = registration; |
||||
console.log('[SW] registration successful with scope: ', swRegistration.scope); |
||||
console.log('[SW] is waiting: ', swRegistration.waiting); |
||||
|
||||
navigator.serviceWorker.addEventListener('controllerchange', function () { |
||||
if (isRefreshing) { |
||||
return; |
||||
} |
||||
window.location.reload(); |
||||
isRefreshing = true; |
||||
}); |
||||
}, function (err) { |
||||
console.log('[SW] registration failed: ', err); |
||||
}); |
||||
}); |
||||
} |
||||
})(); |
@ -1,41 +1,51 @@ |
||||
{ |
||||
"name": "App", |
||||
"icons": [ |
||||
{ |
||||
"src": "\/android-icon-36x36.png", |
||||
"sizes": "36x36", |
||||
"type": "image\/png", |
||||
"density": "0.75" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-48x48.png", |
||||
"sizes": "48x48", |
||||
"type": "image\/png", |
||||
"density": "1.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-72x72.png", |
||||
"sizes": "72x72", |
||||
"type": "image\/png", |
||||
"density": "1.5" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-96x96.png", |
||||
"sizes": "96x96", |
||||
"type": "image\/png", |
||||
"density": "2.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-144x144.png", |
||||
"sizes": "144x144", |
||||
"type": "image\/png", |
||||
"density": "3.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-192x192.png", |
||||
"sizes": "192x192", |
||||
"type": "image\/png", |
||||
"density": "4.0" |
||||
} |
||||
] |
||||
"name": "M-Labs", |
||||
"short_name": "M-Labs", |
||||
"start_url": "/", |
||||
"background_color": "#fff", |
||||
"display": "standalone", |
||||
"theme_color": "#715ec7", |
||||
"icons": [ |
||||
{ |
||||
"src": "\/android-icon-36x36.png", |
||||
"sizes": "36x36", |
||||
"type": "image\/png", |
||||
"density": "0.75" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-48x48.png", |
||||
"sizes": "48x48", |
||||
"type": "image\/png", |
||||
"density": "1.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-72x72.png", |
||||
"sizes": "72x72", |
||||
"type": "image\/png", |
||||
"density": "1.5" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-96x96.png", |
||||
"sizes": "96x96", |
||||
"type": "image\/png", |
||||
"density": "2.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-144x144.png", |
||||
"sizes": "144x144", |
||||
"type": "image\/png", |
||||
"density": "3.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-192x192.png", |
||||
"sizes": "192x192", |
||||
"type": "image\/png", |
||||
"density": "4.0" |
||||
}, |
||||
{ |
||||
"src": "\/android-icon-512x512.png", |
||||
"sizes": "512x512", |
||||
"type": "image\/png" |
||||
} |
||||
] |
||||
} |
@ -0,0 +1,48 @@ |
||||
var CACHE_NAME = 'ml-02'; |
||||
var urlsToCache = [ |
||||
'/css/bootstrap-4.3.1.min.css', |
||||
'/css/styles.css', |
||||
'/js/jquery-3.3.1.slim.min.js', |
||||
'/js/bootstrap-4.3.1.min.js', |
||||
'/js/popper-1.14.7.min.js', |
||||
'/js/hammer-2.0.8.js', |
||||
'/js/three-r76.js', |
||||
'/js/SolveSpaceControls.js', |
||||
'/js/SolveSpaceControls.js', |
||||
'/js/models/kf25.js', |
||||
'/js/models/viewport.js', |
||||
'/js/models/multiport.js', |
||||
'/js/models/chamber.js', |
||||
'/js/models/k526s-body.js', |
||||
'/js/models/k526s-head.js', |
||||
'/js/models/k526s-fixture.js', |
||||
'/js/models/k526s-adapter.js', |
||||
'/js/models/k526s-adapter-assy.js', |
||||
]; |
||||
|
||||
self.addEventListener('install', function(event) { |
||||
console.log('[SW] Install'); |
||||
event.waitUntil( |
||||
caches.open(CACHE_NAME) |
||||
.then(function(cache) { |
||||
console.log('[SW] add to cache'); |
||||
return cache.addAll(urlsToCache); |
||||
}) |
||||
); |
||||
}); |
||||
|
||||
self.addEventListener('fetch', function (event) { |
||||
console.log('[SW] Fetch'); |
||||
event.respondWith( |
||||
caches.match(event.request).then(function (response) { |
||||
return response || fetch(event.request); |
||||
}) |
||||
); |
||||
}); |
||||
|
||||
self.addEventListener('message', function (event) { |
||||
if (event.data.action === 'skipWaiting') { |
||||
self.skipWaiting(); |
||||
caches.delete(CACHE_NAME); |
||||
} |
||||
}); |
Loading…
Reference in new issue