15 lines
530 B
TypeScript
15 lines
530 B
TypeScript
|
|
// Reaktiver Online-Status, basierend auf navigator.onLine + events.
|
||
|
|
// Bewusst kein aktives Heuristik-Probing (Test-Fetches) — für unsere
|
||
|
|
// Zwecke reicht der Browser-Status.
|
||
|
|
class NetworkStore {
|
||
|
|
online = $state(typeof navigator === 'undefined' ? true : navigator.onLine);
|
||
|
|
|
||
|
|
init(): void {
|
||
|
|
if (typeof window === 'undefined') return;
|
||
|
|
window.addEventListener('online', () => (this.online = true));
|
||
|
|
window.addEventListener('offline', () => (this.online = false));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
export const network = new NetworkStore();
|