mirror of
https://github.com/EDCD/coriolis.git
synced 2025-12-08 22:33:24 +00:00
use register-service-worker
This commit is contained in:
@@ -139,6 +139,7 @@
|
|||||||
"react-ga": "^2.5.3",
|
"react-ga": "^2.5.3",
|
||||||
"react-number-editor": "Athanasius/react-number-editor.git#miggy",
|
"react-number-editor": "Athanasius/react-number-editor.git#miggy",
|
||||||
"recharts": "^1.2.0",
|
"recharts": "^1.2.0",
|
||||||
|
"register-service-worker": "^1.5.2",
|
||||||
"superagent": "^3.8.3"
|
"superagent": "^3.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import Router from './Router';
|
import Router from './Router';
|
||||||
|
import { register } from 'register-service-worker'
|
||||||
import { EventEmitter } from 'fbemitter';
|
import { EventEmitter } from 'fbemitter';
|
||||||
import { getLanguage } from './i18n/Language';
|
import { getLanguage } from './i18n/Language';
|
||||||
import Persist from './stores/Persist';
|
import Persist from './stores/Persist';
|
||||||
@@ -349,39 +350,29 @@ export default class Coriolis extends React.Component {
|
|||||||
// *Don't* register service worker file in, e.g., a scripts/ sub-directory!
|
// *Don't* register service worker file in, e.g., a scripts/ sub-directory!
|
||||||
// See https://github.com/slightlyoff/ServiceWorker/issues/468
|
// See https://github.com/slightlyoff/ServiceWorker/issues/468
|
||||||
const self = this;
|
const self = this;
|
||||||
navigator.serviceWorker.register('/service-worker.js').then(function(reg) {
|
register('/service-worker.js', {
|
||||||
// updatefound is fired if service-worker.js changes.
|
ready (registration) {
|
||||||
reg.onupdatefound = function() {
|
console.log('Service worker is active.')
|
||||||
// The updatefound event implies that reg.installing is set; see
|
},
|
||||||
// https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#service-worker-container-updatefound-event
|
registered (registration) {
|
||||||
var installingWorker = reg.installing;
|
console.log('Service worker has been registered.')
|
||||||
|
},
|
||||||
installingWorker.onstatechange = function() {
|
cached (registration) {
|
||||||
switch (installingWorker.state) {
|
console.log('Content has been cached for offline use.')
|
||||||
case 'installed':
|
},
|
||||||
if (navigator.serviceWorker.controller) {
|
updatefound (registration) {
|
||||||
// At this point, the old content will have been purged and the fresh content will
|
console.log('New content is downloading.')
|
||||||
// have been added to the cache.
|
},
|
||||||
// It's the perfect time to display a "New content is available; please refresh."
|
updated (registration) {
|
||||||
// message in the page's interface.
|
self.setState({ appCacheUpdate: true });
|
||||||
console.log('New or updated content is available.');
|
console.log('New content is available; please refresh.')
|
||||||
self.setState({ appCacheUpdate: true }); // Browser downloaded a new app cache.
|
},
|
||||||
} else {
|
offline () {
|
||||||
// At this point, everything has been precached.
|
console.log('No internet connection found. App is running in offline mode.')
|
||||||
// It's the perfect time to display a "Content is cached for offline use." message.
|
},
|
||||||
console.log('Content is now available offline!');
|
error (error) {
|
||||||
self.setState({ appCacheUpdate: true }); // Browser downloaded a new app cache.
|
console.error('Error during service worker registration:', error)
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
|
|
||||||
case 'redundant':
|
|
||||||
console.error('The installing service worker became redundant.');
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}).catch(function(e) {
|
|
||||||
console.error('Error during service worker registration:', e);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ const API_ORBIS = 'https://orbis.zone/api/builds/add';
|
|||||||
* @return {Promise<any>} Either a URL or error message.
|
* @return {Promise<any>} Either a URL or error message.
|
||||||
*/
|
*/
|
||||||
export function orbisUpload(ship, creds) {
|
export function orbisUpload(ship, creds) {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async(resolve, reject) => {
|
||||||
if (window.navigator.onLine) {
|
if (window.navigator.onLine) {
|
||||||
try {
|
try {
|
||||||
agent
|
agent
|
||||||
|
|||||||
Reference in New Issue
Block a user