Skip to content

Commit

Permalink
fix(app): never idle the screen if the config value is the magic idle…
Browse files Browse the repository at this point in the history
… number
  • Loading branch information
mjhuff committed Jan 2, 2025
1 parent da6cdd6 commit 4206e38
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/src/local-resources/dom-utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
// See RQA-3813 and associated PR.
export const SLEEP_NEVER_MS = 604800000
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { renderHook } from '@testing-library/react'
import { useScreenIdle } from '../useScreenIdle'
import { SLEEP_NEVER_MS } from '/app/local-resources/dom-utils'

const MOCK_EVENTS: Array<keyof DocumentEventMap> = [
'mousedown',
Expand Down Expand Up @@ -65,4 +66,13 @@ describe('useIdle', () => {
expect(result.current).toBe(true)
}, 3600001)
})

it(`should always return false if the idle time is exactly ${SLEEP_NEVER_MS}`, () => {
const mockTime = SLEEP_NEVER_MS
const { result } = renderHook(() => useScreenIdle(mockTime, MOCK_OPTIONS))
expect(result.current).toBe(false)
setTimeout(() => {
expect(result.current).toBe(false)
}, 604800001)
})
})
10 changes: 7 additions & 3 deletions app/src/local-resources/dom-utils/hooks/useScreenIdle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useState, useEffect, useRef } from 'react'
import { SLEEP_NEVER_MS } from '/app/local-resources/dom-utils'

const USER_EVENTS: Array<keyof DocumentEventMap> = [
'click',
Expand Down Expand Up @@ -48,9 +49,12 @@ export function useScreenIdle(
window.clearTimeout(idleTimer.current)
}

idleTimer.current = window.setTimeout(() => {
setIdle(true)
}, idleTime)
// See RQA-3813 and associated PR.
if (idleTime !== SLEEP_NEVER_MS) {
idleTimer.current = window.setTimeout(() => {
setIdle(true)
}, idleTime)
}
}

events.forEach(event => {
Expand Down

0 comments on commit 4206e38

Please sign in to comment.