-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathuseIsAway.ts
More file actions
24 lines (21 loc) · 823 Bytes
/
useIsAway.ts
File metadata and controls
24 lines (21 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { createSharedComposable } from '@vueuse/core'
import { computed } from 'vue'
import { useAppIdle } from './useAppIdle.ts'
import { useIdleDetector } from './useIdleDetector.ts'
/**
* Whether the user is away or active
*
* @param threshold - How long user is considered active
*/
export const useIsAway = createSharedComposable((threshold = 60_000) => {
const { userState, screenState } = useIdleDetector(threshold)
const isAppIdle = useAppIdle(threshold)
return computed(() => {
return screenState.value === 'locked' // System Locked - the user is away immediately
|| (userState.value !== 'active' && isAppIdle.value) // Check both to cover unavailable IdleDetector
})
})