forked from ultraworkers/claw-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuseAutoModeUnavailableNotification.ts
More file actions
56 lines (49 loc) · 1.92 KB
/
Copy pathuseAutoModeUnavailableNotification.ts
File metadata and controls
56 lines (49 loc) · 1.92 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { feature } from 'bun:bundle'
import { useEffect, useRef } from 'react'
import { useNotifications } from 'src/context/notifications.js'
import { getIsRemoteMode } from '../../bootstrap/state.js'
import { useAppState } from '../../state/AppState.js'
import type { PermissionMode } from '../../utils/permissions/PermissionMode.js'
import {
getAutoModeUnavailableNotification,
getAutoModeUnavailableReason,
} from '../../utils/permissions/permissionSetup.js'
import { hasAutoModeOptIn } from '../../utils/settings/settings.js'
/**
* Shows a one-shot notification when the shift-tab carousel wraps past where
* auto mode would have been. Covers all reasons (settings, circuit-breaker,
* org-allowlist). The startup case (defaultMode: auto silently downgraded) is
* handled by verifyAutoModeGateAccess → checkAndDisableAutoModeIfNeeded.
*/
export function useAutoModeUnavailableNotification(): void {
const { addNotification } = useNotifications()
const mode = useAppState(s => s.toolPermissionContext.mode)
const isAutoModeAvailable = useAppState(
s => s.toolPermissionContext.isAutoModeAvailable,
)
const shownRef = useRef(false)
const prevModeRef = useRef<PermissionMode>(mode)
useEffect(() => {
const prevMode = prevModeRef.current
prevModeRef.current = mode
if (!feature('TRANSCRIPT_CLASSIFIER')) return
if (getIsRemoteMode()) return
if (shownRef.current) return
const wrappedPastAutoSlot =
mode === 'default' &&
prevMode !== 'default' &&
prevMode !== 'auto' &&
!isAutoModeAvailable &&
hasAutoModeOptIn()
if (!wrappedPastAutoSlot) return
const reason = getAutoModeUnavailableReason()
if (!reason) return
shownRef.current = true
addNotification({
key: 'auto-mode-unavailable',
text: getAutoModeUnavailableNotification(reason),
color: 'warning',
priority: 'medium',
})
}, [mode, isAutoModeAvailable, addNotification])
}