mirror of
https://github.com/misskey-dev/misskey
synced 2025-09-18 17:20:26 +02:00
25 lines
619 B
TypeScript
25 lines
619 B
TypeScript
/*
|
|
* 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;
|
|
}
|