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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import React, { useState } from 'react';
import { Config, sessionId } from '@google/gemini-cli-core';
import { loadSettings, LoadedSettings } from '../config/settings.js';
import { themeManager } from './themes/theme-manager.js';
import { SettingsContext } from './contexts/SettingsContext.js';
import { AppWrapper } from './App.js';
import { loadCliConfig, CliArgs } from '../config/config.js';
import { Extension } from '../config/extension.js';
interface MainComponentProps {
initialConfig: Config;
settings: LoadedSettings;
startupWarnings: string[];
version: string;
workspaceRoot: string;
extensions: Extension[];
argv: CliArgs;
}
export const MainComponent = ({
initialConfig,
settings,
startupWarnings,
version,
workspaceRoot,
extensions,
argv,
}: MainComponentProps) => {
const [currentSettings, setCurrentSettings] =
useState<LoadedSettings>(settings);
const [config, setConfig] = useState<Config>(initialConfig);
const recomputeSettings = () => {
const newSettings = loadSettings(workspaceRoot);
setCurrentSettings(newSettings);
};
React.useEffect(() => {
const recomputeConfigAndTheme = async () => {
// Don't run on initial mount, since the initial config is correct.
if (currentSettings === settings) {
return;
}
// Reload config
const newConfig = await loadCliConfig(
currentSettings.merged,
extensions,
sessionId,
argv,
);
await newConfig.initialize();
if (newConfig.getIdeMode()) {
await newConfig.getIdeClient().connect();
}
// Reload themes
themeManager.loadCustomThemes(currentSettings.merged.customThemes);
if (currentSettings.merged.theme) {
if (!themeManager.setActiveTheme(currentSettings.merged.theme)) {
console.warn(
`Warning: Theme "${currentSettings.merged.theme}" not found.`,
);
}
}
setConfig(newConfig);
};
recomputeConfigAndTheme();
}, [currentSettings, settings, extensions, argv, workspaceRoot]);
const contextValue = {
settings: currentSettings,
recomputeSettings,
};
return (
<React.StrictMode>
<SettingsContext.Provider value={contextValue}>
<AppWrapper
config={config}
startupWarnings={startupWarnings}
version={version}
/>
</SettingsContext.Provider>
</React.StrictMode>
);
};
|