forked from vikunja/frontend
konrad
5724b98358
Merge branch 'master' into feature/vuex Cleanup Move namespaces handling to store Move fullpage setting to store Move online/offline handling to store Remove debug log Fix loading namepaces Rename errorMsg Handle registering through the store Use store to determine wether or not a user is authenticated on login page Use store in edit team Use store to get the current user's avatar Use store to figure out if the current user belongs to a team Use store to figure out if the current user is list admin Use store to get user info when listing labels Use store to get username on home Use store to figure out if the user is namespace admin Use the store for configuration Use the store to check if a user is authenticated everywhere Only renew token if the user is logged in Fix renewing auth from jwt token Move logout to store Move renew token to store Move log in to store Only show enabled migrators Only show registration button if registration is enabled Put all config information from the backend in the store Remove old config handler Move config state to seperate module Add vuex and get the motd through it Co-authored-by: kolaente <k@knt.li> Reviewed-on: vikunja/frontend#126
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
/* eslint-disable no-console */
|
|
|
|
import { register } from 'register-service-worker'
|
|
import swEvents from './ServiceWorker/events'
|
|
|
|
if (process.env.NODE_ENV === 'production') {
|
|
register(`${process.env.BASE_URL}sw.js`, {
|
|
ready () {
|
|
console.log('App is being served from cache by a service worker.')
|
|
},
|
|
registered () {
|
|
console.log('Service worker has been registered.')
|
|
},
|
|
cached () {
|
|
console.log('Content has been cached for offline use.')
|
|
},
|
|
updatefound () {
|
|
console.log('New content is downloading.')
|
|
},
|
|
updated (registration) {
|
|
console.log('New content is available; please refresh.')
|
|
// Send an event with the updated info
|
|
document.dispatchEvent(
|
|
new CustomEvent(swEvents.SW_UPDATED, { detail:registration })
|
|
)
|
|
},
|
|
offline () {
|
|
console.log('No internet connection found. App is running in offline mode.')
|
|
},
|
|
error (error) {
|
|
console.error('Error during service worker registration:', error)
|
|
}
|
|
})
|
|
}
|
|
|
|
if(navigator && navigator.serviceWorker) {
|
|
navigator.serviceWorker.addEventListener('message', event => {
|
|
// for every message we expect an action field
|
|
// determining operation that we should perform
|
|
const { action } = event.data;
|
|
// we use 2nd port provided by the message channel
|
|
const port = event.ports[0];
|
|
|
|
if(action === 'getBearerToken') {
|
|
console.debug('Token request from sw');
|
|
port.postMessage({
|
|
authToken: localStorage.getItem('token'),
|
|
})
|
|
} else {
|
|
console.error('Unknown event', event);
|
|
port.postMessage({
|
|
error: 'Unknown request',
|
|
})
|
|
}
|
|
});
|
|
}
|
|
|