Skip to content

Commit c2c8a67

Browse files
committed
Only show screen reader notice once (#12247)
1 parent a2cb116 commit c2c8a67

1 file changed

Lines changed: 51 additions & 6 deletions

File tree

packages/cli/src/ui/components/Notifications.tsx

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,86 @@
55
*/
66

77
import { Box, Text, useIsScreenReaderEnabled } from 'ink';
8+
import { useEffect, useState } from 'react';
89
import { useAppContext } from '../contexts/AppContext.js';
910
import { useUIState } from '../contexts/UIStateContext.js';
1011
import { theme } from '../semantic-colors.js';
1112
import { StreamingState } from '../types.js';
1213
import { UpdateNotification } from './UpdateNotification.js';
1314

14-
import { GEMINI_DIR } from '@google/gemini-cli-core';
15-
import { homedir } from 'node:os';
15+
import { GEMINI_DIR, Storage } from '@google/gemini-cli-core';
16+
17+
import * as fs from 'node:fs/promises';
18+
import os from 'node:os';
1619
import path from 'node:path';
1720

18-
const settingsPath = path.join(homedir(), GEMINI_DIR, 'settings.json');
21+
const settingsPath = path.join(os.homedir(), GEMINI_DIR, 'settings.json');
22+
23+
const screenReaderNudgeFilePath = path.join(
24+
Storage.getGlobalTempDir(),
25+
'seen_screen_reader_nudge.json',
26+
);
1927

2028
export const Notifications = () => {
2129
const { startupWarnings } = useAppContext();
2230
const { initError, streamingState, updateInfo } = useUIState();
31+
2332
const isScreenReaderEnabled = useIsScreenReaderEnabled();
2433
const showStartupWarnings = startupWarnings.length > 0;
2534
const showInitError =
2635
initError && streamingState !== StreamingState.Responding;
2736

37+
const [hasSeenScreenReaderNudge, setHasSeenScreenReaderNudge] = useState<
38+
boolean | undefined
39+
>(undefined);
40+
41+
useEffect(() => {
42+
const checkScreenReaderNudge = async () => {
43+
try {
44+
await fs.access(screenReaderNudgeFilePath);
45+
setHasSeenScreenReaderNudge(true);
46+
} catch {
47+
setHasSeenScreenReaderNudge(false);
48+
}
49+
};
50+
checkScreenReaderNudge();
51+
}, []);
52+
53+
const showScreenReaderNudge =
54+
isScreenReaderEnabled && !hasSeenScreenReaderNudge;
55+
56+
useEffect(() => {
57+
const writeScreenReaderNudgeFile = async () => {
58+
if (showScreenReaderNudge) {
59+
try {
60+
await fs.mkdir(path.dirname(screenReaderNudgeFilePath), {
61+
recursive: true,
62+
});
63+
await fs.writeFile(screenReaderNudgeFilePath, 'true');
64+
} catch (error) {
65+
console.error('Error storing screen reader nudge', error);
66+
}
67+
}
68+
};
69+
writeScreenReaderNudgeFile();
70+
}, [showScreenReaderNudge]);
71+
2872
if (
2973
!showStartupWarnings &&
3074
!showInitError &&
3175
!updateInfo &&
32-
!isScreenReaderEnabled
76+
!showScreenReaderNudge
3377
) {
3478
return null;
3579
}
3680

3781
return (
3882
<>
39-
{isScreenReaderEnabled && (
83+
{showScreenReaderNudge && (
4084
<Text>
4185
You are currently in screen reader-friendly view. To switch out, open{' '}
42-
{settingsPath} and remove the entry for {'"screenReader"'}.
86+
{settingsPath} and remove the entry for {'"screenReader"'}. This will
87+
disappear on next run.
4388
</Text>
4489
)}
4590
{updateInfo && <UpdateNotification message={updateInfo.message} />}

0 commit comments

Comments
 (0)