blob: a87c1f1bab15f35b94711bed6795a04ce2aebabe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { onMounted, onUnmounted, ref } from 'vue';
import type { Ref } from 'vue';
export function useDocumentVisibility(): Ref<DocumentVisibilityState> {
const visibility = ref(window.document.visibilityState);
const onChange = (): void => {
visibility.value = window.document.visibilityState;
};
onMounted(() => {
window.document.addEventListener('visibilitychange', onChange);
});
onUnmounted(() => {
window.document.removeEventListener('visibilitychange', onChange);
});
return visibility;
}
|