Only show screen reader notice once (#12247)

This commit is contained in:
christine betts
2025-11-03 18:04:48 -08:00
committed by GitHub
parent bd06e5b161
commit fc42c4613f

View File

@@ -5,41 +5,86 @@
*/
import { Box, Text, useIsScreenReaderEnabled } from 'ink';
import { useEffect, useState } from 'react';
import { useAppContext } from '../contexts/AppContext.js';
import { useUIState } from '../contexts/UIStateContext.js';
import { theme } from '../semantic-colors.js';
import { StreamingState } from '../types.js';
import { UpdateNotification } from './UpdateNotification.js';
import { GEMINI_DIR } from '@google/gemini-cli-core';
import { homedir } from 'node:os';
import { GEMINI_DIR, Storage } from '@google/gemini-cli-core';
import * as fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
const settingsPath = path.join(homedir(), GEMINI_DIR, 'settings.json');
const settingsPath = path.join(os.homedir(), GEMINI_DIR, 'settings.json');
const screenReaderNudgeFilePath = path.join(
Storage.getGlobalTempDir(),
'seen_screen_reader_nudge.json',
);
export const Notifications = () => {
const { startupWarnings } = useAppContext();
const { initError, streamingState, updateInfo } = useUIState();
const isScreenReaderEnabled = useIsScreenReaderEnabled();
const showStartupWarnings = startupWarnings.length > 0;
const showInitError =
initError && streamingState !== StreamingState.Responding;
const [hasSeenScreenReaderNudge, setHasSeenScreenReaderNudge] = useState<
boolean | undefined
>(undefined);
useEffect(() => {
const checkScreenReaderNudge = async () => {
try {
await fs.access(screenReaderNudgeFilePath);
setHasSeenScreenReaderNudge(true);
} catch {
setHasSeenScreenReaderNudge(false);
}
};
checkScreenReaderNudge();
}, []);
const showScreenReaderNudge =
isScreenReaderEnabled && !hasSeenScreenReaderNudge;
useEffect(() => {
const writeScreenReaderNudgeFile = async () => {
if (showScreenReaderNudge) {
try {
await fs.mkdir(path.dirname(screenReaderNudgeFilePath), {
recursive: true,
});
await fs.writeFile(screenReaderNudgeFilePath, 'true');
} catch (error) {
console.error('Error storing screen reader nudge', error);
}
}
};
writeScreenReaderNudgeFile();
}, [showScreenReaderNudge]);
if (
!showStartupWarnings &&
!showInitError &&
!updateInfo &&
!isScreenReaderEnabled
!showScreenReaderNudge
) {
return null;
}
return (
<>
{isScreenReaderEnabled && (
{showScreenReaderNudge && (
<Text>
You are currently in screen reader-friendly view. To switch out, open{' '}
{settingsPath} and remove the entry for {'"screenReader"'}.
{settingsPath} and remove the entry for {'"screenReader"'}. This will
disappear on next run.
</Text>
)}
{updateInfo && <UpdateNotification message={updateInfo.message} />}