mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
19 lines
532 B
TypeScript
19 lines
532 B
TypeScript
export function registerNodeWardenServiceWorker(): void {
|
|
if (typeof window === 'undefined') return;
|
|
if (!('serviceWorker' in navigator)) return;
|
|
if (import.meta.env.DEV) return;
|
|
|
|
const register = () => {
|
|
void navigator.serviceWorker.register('/sw.js', { scope: '/' }).catch(() => {
|
|
// PWA support is progressive enhancement; the vault still works without it.
|
|
});
|
|
};
|
|
|
|
if (document.readyState === 'complete') {
|
|
register();
|
|
return;
|
|
}
|
|
|
|
window.addEventListener('load', register, { once: true });
|
|
}
|