Commit 225c315e authored by Xavier Guimard's avatar Xavier Guimard Committed by Xavier Guimard

Add minimal service worker (#1677)

parent 3cea903c
Pipeline #4776 passed with stage
in 10 minutes and 2 seconds
......@@ -15,6 +15,19 @@ llapp = angular.module 'llngManager', ['ui.tree', 'ui.bootstrap', 'llApp', 'ngCo
Main AngularJS controller
###
if navigator.serviceWorker
navigator.serviceWorker.register('/static/js/sw.js', {scope: '/static/', insecure: true}).then (reg) =>
if reg.installing
console.log 'Service worker installing'
else if reg.waiting
console.log 'Service worker installed'
else if reg.active
console.log 'Service worker active'
.catch (error) =>
console.log 'Registration failed with ' + error
else
console.error 'No serviceWorker in navigator'
llapp.controller 'TreeCtrl', [
'$scope', '$http', '$location', '$q', '$uibModal', '$translator', '$cookies', '$htmlParams',
($scope, $http, $location, $q, $uibModal, $translator, $cookies, $htmlParams) ->
......
self.addEventListener 'install', (event) =>
event.waitUntil caches.open('v1').then (cache) =>
return cache.addAll [
'/static/struct.json',
'/static/form/home.html',
'/static/form/keyText.html',
'/static/form/bool.html',
'/static/form/boolOrExpr.html',
]
self.addEventListener 'fetch', (event) =>
event.respondWith caches.match(event.request).then (response) =>
if response != undefined
return response
else
return fetch(event.request).then (response) =>
responseClone = response.clone()
caches.open('v1').then (cache) =>
cache.put event.request, responseClone
response
.catch () =>
alert 'Network error'
......@@ -21,6 +21,29 @@ This file contains:
Main AngularJS controller
*/
if (navigator.serviceWorker) {
navigator.serviceWorker.register('/static/js/sw.js', {
scope: '/static/',
insecure: true
}).then((function(_this) {
return function(reg) {
if (reg.installing) {
return console.log('Service worker installing');
} else if (reg.waiting) {
return console.log('Service worker installed');
} else if (reg.active) {
return console.log('Service worker active');
}
};
})(this))["catch"]((function(_this) {
return function(error) {
return console.log('Registration failed with ' + error);
};
})(this));
} else {
console.error('No serviceWorker in navigator');
}
llapp.controller('TreeCtrl', [
'$scope', '$http', '$location', '$q', '$uibModal', '$translator', '$cookies', '$htmlParams', function($scope, $http, $location, $q, $uibModal, $translator, $cookies, $htmlParams) {
var _checkSaveResponse, _download, _getAll, _stoggle, c, id, pathEvent, readError, setDefault, setHelp;
......
// Generated by CoffeeScript 1.12.8
(function() {
self.addEventListener('install', (function(_this) {
return function(event) {
return event.waitUntil(caches.open('v1').then(function(cache) {
return cache.addAll(['/static/struct.json', '/static/form/home.html', '/static/form/keyText.html', '/static/form/bool.html', '/static/form/boolOrExpr.html']);
}));
};
})(this));
self.addEventListener('fetch', (function(_this) {
return function(event) {
return event.respondWith(caches.match(event.request).then(function(response) {
if (response !== void 0) {
return response;
} else {
return fetch(event.request).then(function(response) {
var responseClone;
responseClone = response.clone();
caches.open('v1').then(function(cache) {
return cache.put(event.request, responseClone);
});
return response;
})["catch"](function() {
return alert('Network error');
});
}
}));
};
})(this));
}).call(this);
(function(){self.addEventListener("install",function(_this){return function(event){return event.waitUntil(caches.open("v1").then(function(cache){return cache.addAll(["/static/struct.json","/static/form/home.html","/static/form/keyText.html","/static/form/bool.html","/static/form/boolOrExpr.html"])}))}}(this));self.addEventListener("fetch",function(_this){return function(event){return event.respondWith(caches.match(event.request).then(function(response){if(response!==void 0){return response}else{return fetch(event.request).then(function(response){var responseClone;responseClone=response.clone();caches.open("v1").then(function(cache){return cache.put(event.request,responseClone)});return response})["catch"](function(){return alert("Network error")})}}))}}(this))}).call(this);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment