fix: pass startup warnings to app as prop (#342)

This commit is contained in:
Brandon Keiji
2025-05-14 00:12:04 +00:00
committed by GitHub
parent d3303fd3a0
commit 7116ab9c29
4 changed files with 50 additions and 47 deletions

View File

@@ -16,7 +16,6 @@ import { LoadingIndicator } from './components/LoadingIndicator.js';
import { EditorState, InputPrompt } from './components/InputPrompt.js';
import { Footer } from './components/Footer.js';
import { ThemeDialog } from './components/ThemeDialog.js';
import { useStartupWarnings } from './hooks/useAppEffects.js';
import { shortenPath, type Config } from '@gemini-code/server';
import { Colors } from './colors.js';
import { Help } from './components/Help.js';
@@ -33,16 +32,21 @@ interface AppProps {
config: Config;
settings: LoadedSettings;
cliVersion: string;
startupWarnings?: string[];
}
export const App = ({ config, settings, cliVersion }: AppProps) => {
export const App = ({
config,
settings,
cliVersion,
startupWarnings = [],
}: AppProps) => {
const { history, addItem, clearItems } = useHistory();
const [staticKey, setStaticKey] = useState(0);
const refreshStatic = useCallback(() => {
setStaticKey((prev) => prev + 1);
}, [setStaticKey]);
const [startupWarnings, setStartupWarnings] = useState<string[]>([]);
const [debugMessage, setDebugMessage] = useState<string>('');
const [showHelp, setShowHelp] = useState<boolean>(false);
const [themeError, setThemeError] = useState<string | null>(null);
@@ -74,8 +78,6 @@ export const App = ({ config, settings, cliVersion }: AppProps) => {
const { elapsedTime, currentLoadingPhrase } =
useLoadingIndicator(streamingState);
useStartupWarnings(setStartupWarnings);
const handleFinalSubmit = useCallback(
(submittedValue: string) => {
const trimmedValue = submittedValue.trim();

View File

@@ -1,42 +0,0 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { useEffect } from 'react';
import fs from 'fs';
import path from 'path';
import os from 'os';
import { getErrorMessage } from '@gemini-code/server';
const warningsFilePath = path.join(os.tmpdir(), 'gemini-code-cli-warnings.txt');
// Effect to handle startup warnings
export function useStartupWarnings(
setStartupWarnings: React.Dispatch<React.SetStateAction<string[]>>,
) {
useEffect(() => {
try {
if (fs.existsSync(warningsFilePath)) {
const warningsContent = fs.readFileSync(warningsFilePath, 'utf-8');
setStartupWarnings(
warningsContent.split('\n').filter((line) => line.trim() !== ''),
);
try {
fs.unlinkSync(warningsFilePath);
} catch {
setStartupWarnings((prev) => [
...prev,
`Warning: Could not delete temporary warnings file.`,
]);
}
}
} catch (err: unknown) {
setStartupWarnings((prev) => [
...prev,
`Error checking/reading warnings file: ${getErrorMessage(err)}`,
]);
}
}, [setStartupWarnings]); // Include setStartupWarnings in dependency array
}