mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 14:33:22 +00:00
sw work
This commit is contained in:
@@ -81,6 +81,7 @@ export default class Header extends TranslatedComponent {
|
||||
this._getAnnouncementsMenu = this._getAnnouncementsMenu.bind(this);
|
||||
this._openSettings = this._openMenu.bind(this, 'settings');
|
||||
this._showHelp = this._showHelp.bind(this);
|
||||
this.update = this.update.bind(this);
|
||||
this.languageOptions = [];
|
||||
this.insuranceOptions = [];
|
||||
this.state = {
|
||||
@@ -560,6 +561,15 @@ export default class Header extends TranslatedComponent {
|
||||
}
|
||||
}
|
||||
|
||||
async update() {
|
||||
const reg = await navigator.serviceWorker.getRegistration();
|
||||
if (!reg || !reg.waiting) {
|
||||
return;
|
||||
}
|
||||
reg.waiting.postMessage('skipWaiting');
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the header
|
||||
* @return {React.Component} Header
|
||||
@@ -570,7 +580,7 @@ export default class Header extends TranslatedComponent {
|
||||
let hasBuilds = Persist.hasBuilds();
|
||||
return (
|
||||
<header>
|
||||
{this.props.appCacheUpdate && <div id="app-update" onClick={() => window.location.reload() }>{translate('PHRASE_UPDATE_RDY')}</div>}
|
||||
{this.props.appCacheUpdate && <div id="app-update" onClick={this.update}>{translate('PHRASE_UPDATE_RDY')}</div>}
|
||||
{this.props.appCacheUpdate ? <a className={'view-changes'} href={'https://github.com/EDCD/coriolis/compare/edcd:develop@{' + window.CORIOLIS_DATE + '}...edcd:develop'} target="_blank">
|
||||
{'View Release Changes'}
|
||||
</a> : null}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
"density": "4.0"
|
||||
}
|
||||
],
|
||||
"start_url": "https:\/\/edcd.coriolis.io",
|
||||
"start_url": "https:\/\/coriolis.io",
|
||||
"display": "standalone",
|
||||
"orientation": "portrait"
|
||||
}
|
||||
|
||||
56
src/sw.js
56
src/sw.js
@@ -42,31 +42,39 @@ if (workbox) {
|
||||
} else {
|
||||
console.log('Boo! Workbox didn\'t load 😬');
|
||||
}
|
||||
(async() => {
|
||||
if (event.request.mode === 'navigate' && registration.waiting) {
|
||||
if ((await clients.matchAll()).length < 2) {
|
||||
registration.waiting.postMessage('skipWaiting');
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
addEventListener('message', messageEvent => {
|
||||
if (messageEvent.data === 'skipWaiting') return skipWaiting();
|
||||
|
||||
self.addEventListener('message', event => {
|
||||
if (!event.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.data) {
|
||||
case 'skipWaiting':
|
||||
self.skipWaiting();
|
||||
break;
|
||||
default:
|
||||
// NOOP
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
addEventListener('fetch', event => {
|
||||
event.respondWith(
|
||||
(async() => {
|
||||
if (
|
||||
event.request.mode === 'navigate' &&
|
||||
event.request.method === 'GET' &&
|
||||
registration.waiting &&
|
||||
(await clients.matchAll()).length < 2
|
||||
) {
|
||||
registration.waiting.postMessage('skipWaiting');
|
||||
return new Response('', { headers: { Refresh: '0' } });
|
||||
}
|
||||
return (await caches.match(event.request)) || fetch(event.request);
|
||||
})()
|
||||
);
|
||||
self.addEventListener('fetch', function(event) {
|
||||
console.log('Handling fetch event for', event.request.url);
|
||||
|
||||
event.respondWith(
|
||||
caches.match(event.request).then(function(response) {
|
||||
if (response) {
|
||||
return response;
|
||||
}
|
||||
|
||||
return fetch(event.request)
|
||||
.then(function(response) {
|
||||
return response;
|
||||
})
|
||||
.catch(function(error) {
|
||||
return caches.match(OFFLINE_URL);
|
||||
});
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user