2021-06-25 18:14:40 +02:00
|
|
|
import { readable } from "svelte/store";
|
2021-06-24 11:54:09 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A store containing whether the current page is visible or not.
|
|
|
|
*/
|
2021-06-25 18:14:40 +02:00
|
|
|
export const visibilityStore = readable(document.visibilityState === "visible", function start(set) {
|
2021-06-24 11:54:09 +02:00
|
|
|
const onVisibilityChange = () => {
|
2021-06-25 18:14:40 +02:00
|
|
|
set(document.visibilityState === "visible");
|
2021-06-24 11:54:09 +02:00
|
|
|
};
|
|
|
|
|
2021-06-25 18:14:40 +02:00
|
|
|
document.addEventListener("visibilitychange", onVisibilityChange);
|
2021-06-24 11:54:09 +02:00
|
|
|
|
|
|
|
return function stop() {
|
2021-06-25 18:14:40 +02:00
|
|
|
document.removeEventListener("visibilitychange", onVisibilityChange);
|
2021-06-24 11:54:09 +02:00
|
|
|
};
|
|
|
|
});
|