Working ServiceWorker
This commit is contained in:
parent
1d04f25a0a
commit
e377ec3194
@ -25,29 +25,15 @@ if ('serviceWorker' in navigator) {
|
|||||||
.register()
|
.register()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log('registering service worker');
|
console.log('registering service worker');
|
||||||
|
return navigator.serviceWorker.ready;
|
||||||
if (navigator.serviceWorker.controller) {
|
|
||||||
// already active and controlling this page
|
|
||||||
return navigator.serviceWorker;
|
|
||||||
}
|
|
||||||
// wait for a new service worker to control this page
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
try {
|
|
||||||
const onControllerChange = () => {
|
|
||||||
navigator.serviceWorker.removeEventListener('controllerchange', onControllerChange);
|
|
||||||
resolve(navigator.serviceWorker);
|
|
||||||
};
|
|
||||||
|
|
||||||
navigator.serviceWorker.addEventListener('controllerchange', onControllerChange);
|
|
||||||
} catch (error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.then((_worker) => {
|
.then((registration) => {
|
||||||
|
console.log('registered service worker');
|
||||||
|
|
||||||
|
const _worker = registration.active;
|
||||||
|
_worker.controller = registration.active;
|
||||||
const worker = new PromiseWorker(_worker);
|
const worker = new PromiseWorker(_worker);
|
||||||
|
|
||||||
console.log('registered service worker');
|
|
||||||
return worker;
|
return worker;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -25,10 +25,12 @@ registerPromiseWorker((msg) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('install', (event) => {
|
self.addEventListener('install', (event) => {
|
||||||
|
console.warn('installing sw');
|
||||||
event.waitUntil(self.skipWaiting());
|
event.waitUntil(self.skipWaiting());
|
||||||
});
|
});
|
||||||
|
|
||||||
self.addEventListener('activate', (event) => {
|
self.addEventListener('activate', (event) => {
|
||||||
|
console.warn('activating sw');
|
||||||
event.waitUntil(self.clients.claim());
|
event.waitUntil(self.clients.claim());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,20 +143,21 @@ function fetchSolc (build) {
|
|||||||
|
|
||||||
return fetch(URL)
|
return fetch(URL)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response || response.status !== 200 || response.type !== 'basic') {
|
if (!response || response.status !== 200) {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
const responseToCache = response.clone();
|
const responseToCache = response.clone();
|
||||||
|
|
||||||
caches.open(CACHE_NAME)
|
return caches.open(CACHE_NAME)
|
||||||
.then((cache) => {
|
.then((cache) => {
|
||||||
cache.put(URL, responseToCache);
|
return cache.put(URL, responseToCache);
|
||||||
});
|
})
|
||||||
|
.then(() => {
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function fetchSolidity (build) {
|
function fetchSolidity (build) {
|
||||||
|
@ -74,6 +74,7 @@ export default class WriteContractStore {
|
|||||||
|
|
||||||
@observable workerError = null;
|
@observable workerError = null;
|
||||||
|
|
||||||
|
loadingSolidity = false;
|
||||||
lastCompilation = {};
|
lastCompilation = {};
|
||||||
snippets = SNIPPETS;
|
snippets = SNIPPETS;
|
||||||
worker = null;
|
worker = null;
|
||||||
@ -147,7 +148,11 @@ export default class WriteContractStore {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.worker
|
if (this.loadingSolidity) {
|
||||||
|
return this.loadingSolidity;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.loadingSolidity = this.worker
|
||||||
.postMessage({
|
.postMessage({
|
||||||
action: 'load',
|
action: 'load',
|
||||||
data: build
|
data: build
|
||||||
@ -161,8 +166,11 @@ export default class WriteContractStore {
|
|||||||
this.setWorkerError(error);
|
this.setWorkerError(error);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.loadingSolidity = false;
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return this.loadingSolidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@action handleOpenDeployModal = () => {
|
@action handleOpenDeployModal = () => {
|
||||||
@ -243,7 +251,8 @@ export default class WriteContractStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return promise.then((data = {}) => {
|
return promise.then((data = null) => {
|
||||||
|
if (data) {
|
||||||
const {
|
const {
|
||||||
contract, contractIndex,
|
contract, contractIndex,
|
||||||
annotations, contracts, errors
|
annotations, contracts, errors
|
||||||
@ -255,6 +264,7 @@ export default class WriteContractStore {
|
|||||||
this.annotations = annotations;
|
this.annotations = annotations;
|
||||||
this.contracts = contracts;
|
this.contracts = contracts;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
|
}
|
||||||
|
|
||||||
this.compiled = true;
|
this.compiled = true;
|
||||||
this.compiling = false;
|
this.compiling = false;
|
||||||
|
@ -166,7 +166,7 @@ module.exports = {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
new ServiceWorkerWebpackPlugin({
|
new ServiceWorkerWebpackPlugin({
|
||||||
entry: path.join(__dirname, '../src/serviceWorker.js'),
|
entry: path.join(__dirname, '../src/serviceWorker.js')
|
||||||
}),
|
}),
|
||||||
|
|
||||||
DappsHTMLInjection
|
DappsHTMLInjection
|
||||||
|
Loading…
Reference in New Issue
Block a user