mirror of
https://github.com/zammad/zammad
synced 2026-05-24 09:48:36 +00:00
41 lines
930 B
TypeScript
41 lines
930 B
TypeScript
// Copyright (C) 2012-2026 Zammad Foundation, https://zammad-foundation.org/
|
|
|
|
export class ServiceWorkerHelper {
|
|
private enabled =
|
|
typeof localStorage !== 'undefined' &&
|
|
typeof localStorage.getItem === 'function' &&
|
|
localStorage.getItem('_dev_sw') === 'true'
|
|
|
|
public ontriggerupdate: (() => void) | null = null
|
|
|
|
allow() {
|
|
this.enabled = true
|
|
localStorage.setItem('_dev_sw', 'true')
|
|
window.location.reload()
|
|
}
|
|
|
|
unregister() {
|
|
this.enabled = false
|
|
localStorage.setItem('_dev_sw', 'false')
|
|
navigator.serviceWorker.getRegistrations().then(async (registrations) => {
|
|
await Promise.all(registrations.map((r) => r.unregister()))
|
|
window.location.reload()
|
|
})
|
|
}
|
|
|
|
triggerUpdate() {
|
|
this.ontriggerupdate?.()
|
|
}
|
|
|
|
isEnabled() {
|
|
return this.enabled
|
|
}
|
|
}
|
|
|
|
window.sw = new ServiceWorkerHelper()
|
|
|
|
declare global {
|
|
interface Window {
|
|
sw?: ServiceWorkerHelper
|
|
}
|
|
}
|