offline warning
This commit is contained in:
parent
ec693b9c3f
commit
e2c5eab08b
3 changed files with 99 additions and 1 deletions
24
src/lib/online.svelte.ts
Normal file
24
src/lib/online.svelte.ts
Normal file
|
@ -0,0 +1,24 @@
|
|||
import { writable } from "svelte/store";
|
||||
|
||||
function createOnline() {
|
||||
const { subscribe, set } = writable(navigator.onLine);
|
||||
|
||||
function handleOnline() {
|
||||
set(true);
|
||||
}
|
||||
|
||||
function handleOffline() {
|
||||
set(false);
|
||||
}
|
||||
|
||||
if (typeof window !== "undefined") {
|
||||
window.addEventListener("online", handleOnline);
|
||||
window.addEventListener("offline", handleOffline);
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
};
|
||||
}
|
||||
|
||||
export const online = createOnline();
|
Loading…
Add table
Add a link
Reference in a new issue