summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/hooks/useAppEffects.ts
blob: da1ab2035622d0cd418ca2ae322dba4e57deda98 (plain)
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
/**
 * @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
}