Skip to content

Commit

Permalink
improve serviceworker startup in neutralino
Browse files Browse the repository at this point in the history
  • Loading branch information
hrgdavor committed Jun 29, 2024
1 parent 8e52296 commit d95fa09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
18 changes: 13 additions & 5 deletions apps/jscad-web/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ async function initFs() {
return file
}
let scope = document.location.pathname
sw = await registerServiceWorker(`bundle.fs-serviceworker.js?prefix=${scope}swfs/`, getFileWrapper, {
scope,
prefix: scope + 'swfs/',
})
try{
sw = await registerServiceWorker(`bundle.fs-serviceworker.js?prefix=${scope}swfs/`, getFileWrapper, {
scope,
prefix: scope + 'swfs/',
})
}catch(e){
const lastReload = localStorage.getItem('lastReload')
if (!lastReload || Date.now() - lastReload > 3000) {
localStorage.setItem('lastReload', Date.now())
location.reload()
}
}
sw.defProjectName = 'jscad'
sw.onfileschange = files => {
if (files.includes('/package.json')) {
Expand Down Expand Up @@ -386,7 +394,7 @@ if ('serviceWorker' in navigator && !navigator.serviceWorker.controller) {
if (!lastReload || Date.now() - lastReload > 3000) {
setError('cannot start service worker, reloading')
localStorage.setItem('lastReload', Date.now())
location.reload()
//location.reload()
} else {
console.error('cannot start service worker, reload required')
}
Expand Down
1 change: 1 addition & 0 deletions packages/fs-provider/fs-provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export const registerServiceWorker = async (
// for now we use fetch to extract our id, but a better way could be found later
const id = await fetch(prefix + 'init').then(res => {
if (!res.ok) {
console.error(res)
throw new Error('failed to start service worker')
}
return res.text()
Expand Down

0 comments on commit d95fa09

Please sign in to comment.