Ignore workspace settings for untrusted folders (#6606)
This commit is contained in:
parent
179f1414da
commit
d250293c2e
|
@ -1270,6 +1270,7 @@ describe('Settings Loading and Merging', () => {
|
||||||
expect(loadedSettings.workspace.settings.contextFileName).toBe(
|
expect(loadedSettings.workspace.settings.contextFileName).toBe(
|
||||||
'MY_AGENTS.md',
|
'MY_AGENTS.md',
|
||||||
);
|
);
|
||||||
|
// This test assumes a trusted workspace, so the workspace setting should apply.
|
||||||
expect(loadedSettings.merged.contextFileName).toBe('MY_AGENTS.md');
|
expect(loadedSettings.merged.contextFileName).toBe('MY_AGENTS.md');
|
||||||
expect(loadedSettings.merged.theme).toBe('matrix'); // User setting should still be there
|
expect(loadedSettings.merged.theme).toBe('matrix'); // User setting should still be there
|
||||||
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
expect(fs.writeFileSync).toHaveBeenCalledWith(
|
||||||
|
|
|
@ -16,6 +16,7 @@ import {
|
||||||
import stripJsonComments from 'strip-json-comments';
|
import stripJsonComments from 'strip-json-comments';
|
||||||
import { DefaultLight } from '../ui/themes/default-light.js';
|
import { DefaultLight } from '../ui/themes/default-light.js';
|
||||||
import { DefaultDark } from '../ui/themes/default.js';
|
import { DefaultDark } from '../ui/themes/default.js';
|
||||||
|
import { isWorkspaceTrusted } from './trustedFolders.js';
|
||||||
import { Settings, MemoryImportFormat } from './settingsSchema.js';
|
import { Settings, MemoryImportFormat } from './settingsSchema.js';
|
||||||
|
|
||||||
export type { Settings, MemoryImportFormat };
|
export type { Settings, MemoryImportFormat };
|
||||||
|
@ -73,7 +74,30 @@ function mergeSettings(
|
||||||
system: Settings,
|
system: Settings,
|
||||||
user: Settings,
|
user: Settings,
|
||||||
workspace: Settings,
|
workspace: Settings,
|
||||||
|
isTrusted?: boolean,
|
||||||
): Settings {
|
): Settings {
|
||||||
|
if (!isTrusted) {
|
||||||
|
return {
|
||||||
|
...user,
|
||||||
|
...system,
|
||||||
|
customThemes: {
|
||||||
|
...(user.customThemes || {}),
|
||||||
|
...(system.customThemes || {}),
|
||||||
|
},
|
||||||
|
mcpServers: {
|
||||||
|
...(user.mcpServers || {}),
|
||||||
|
...(system.mcpServers || {}),
|
||||||
|
},
|
||||||
|
includeDirectories: [
|
||||||
|
...(system.includeDirectories || []),
|
||||||
|
...(user.includeDirectories || []),
|
||||||
|
],
|
||||||
|
chatCompression: {
|
||||||
|
...(system.chatCompression || {}),
|
||||||
|
...(user.chatCompression || {}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
// folderTrust is not supported at workspace level.
|
// folderTrust is not supported at workspace level.
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const { folderTrust, ...workspaceWithoutFolderTrust } = workspace;
|
const { folderTrust, ...workspaceWithoutFolderTrust } = workspace;
|
||||||
|
@ -111,11 +135,13 @@ export class LoadedSettings {
|
||||||
user: SettingsFile,
|
user: SettingsFile,
|
||||||
workspace: SettingsFile,
|
workspace: SettingsFile,
|
||||||
errors: SettingsError[],
|
errors: SettingsError[],
|
||||||
|
isTrusted?: boolean,
|
||||||
) {
|
) {
|
||||||
this.system = system;
|
this.system = system;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.workspace = workspace;
|
this.workspace = workspace;
|
||||||
this.errors = errors;
|
this.errors = errors;
|
||||||
|
this.isTrusted = isTrusted;
|
||||||
this._merged = this.computeMergedSettings();
|
this._merged = this.computeMergedSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,6 +149,7 @@ export class LoadedSettings {
|
||||||
readonly user: SettingsFile;
|
readonly user: SettingsFile;
|
||||||
readonly workspace: SettingsFile;
|
readonly workspace: SettingsFile;
|
||||||
readonly errors: SettingsError[];
|
readonly errors: SettingsError[];
|
||||||
|
private isTrusted: boolean | undefined;
|
||||||
|
|
||||||
private _merged: Settings;
|
private _merged: Settings;
|
||||||
|
|
||||||
|
@ -130,11 +157,17 @@ export class LoadedSettings {
|
||||||
return this._merged;
|
return this._merged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
recomputeMergedSettings(isTrusted?: boolean): void {
|
||||||
|
this.isTrusted = isTrusted;
|
||||||
|
this._merged = this.computeMergedSettings();
|
||||||
|
}
|
||||||
|
|
||||||
private computeMergedSettings(): Settings {
|
private computeMergedSettings(): Settings {
|
||||||
return mergeSettings(
|
return mergeSettings(
|
||||||
this.system.settings,
|
this.system.settings,
|
||||||
this.user.settings,
|
this.user.settings,
|
||||||
this.workspace.settings,
|
this.workspace.settings,
|
||||||
|
this.isTrusted,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -403,11 +436,16 @@ export function loadSettings(workspaceDir: string): LoadedSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For the initial trust check, we can only use user and system settings.
|
||||||
|
const initialTrustCheckSettings = { ...systemSettings, ...userSettings };
|
||||||
|
const isTrusted = isWorkspaceTrusted(initialTrustCheckSettings);
|
||||||
|
|
||||||
// Create a temporary merged settings object to pass to loadEnvironment.
|
// Create a temporary merged settings object to pass to loadEnvironment.
|
||||||
const tempMergedSettings = mergeSettings(
|
const tempMergedSettings = mergeSettings(
|
||||||
systemSettings,
|
systemSettings,
|
||||||
userSettings,
|
userSettings,
|
||||||
workspaceSettings,
|
workspaceSettings,
|
||||||
|
isTrusted,
|
||||||
);
|
);
|
||||||
|
|
||||||
// loadEnviroment depends on settings so we have to create a temp version of
|
// loadEnviroment depends on settings so we have to create a temp version of
|
||||||
|
@ -434,6 +472,7 @@ export function loadSettings(workspaceDir: string): LoadedSettings {
|
||||||
settings: workspaceSettings,
|
settings: workspaceSettings,
|
||||||
},
|
},
|
||||||
settingsErrors,
|
settingsErrors,
|
||||||
|
isTrusted,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validate chatCompression settings
|
// Validate chatCompression settings
|
||||||
|
|
|
@ -35,6 +35,10 @@ vi.mock('./config/settings.js', async (importOriginal) => {
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
vi.mock('./config/trustedFolders.js', () => ({
|
||||||
|
isWorkspaceTrusted: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
vi.mock('./config/config.js', () => ({
|
vi.mock('./config/config.js', () => ({
|
||||||
loadCliConfig: vi.fn().mockResolvedValue({
|
loadCliConfig: vi.fn().mockResolvedValue({
|
||||||
config: {
|
config: {
|
||||||
|
@ -149,6 +153,7 @@ describe('gemini.tsx main function', () => {
|
||||||
userSettingsFile,
|
userSettingsFile,
|
||||||
workspaceSettingsFile,
|
workspaceSettingsFile,
|
||||||
[settingsError],
|
[settingsError],
|
||||||
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
loadSettingsMock.mockReturnValue(mockLoadedSettings);
|
loadSettingsMock.mockReturnValue(mockLoadedSettings);
|
||||||
|
|
|
@ -4,9 +4,8 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
|
||||||
import { render } from 'ink';
|
import { render } from 'ink';
|
||||||
import { AppWrapper } from './ui/App.js';
|
import { MainComponent } from './ui/MainComponent.js';
|
||||||
import { loadCliConfig, parseArguments } from './config/config.js';
|
import { loadCliConfig, parseArguments } from './config/config.js';
|
||||||
import { readStdin } from './utils/readStdin.js';
|
import { readStdin } from './utils/readStdin.js';
|
||||||
import { basename } from 'node:path';
|
import { basename } from 'node:path';
|
||||||
|
@ -46,7 +45,6 @@ import { detectAndEnableKittyProtocol } from './ui/utils/kittyProtocolDetector.j
|
||||||
import { checkForUpdates } from './ui/utils/updateCheck.js';
|
import { checkForUpdates } from './ui/utils/updateCheck.js';
|
||||||
import { handleAutoUpdate } from './utils/handleAutoUpdate.js';
|
import { handleAutoUpdate } from './utils/handleAutoUpdate.js';
|
||||||
import { appEvents, AppEvent } from './utils/events.js';
|
import { appEvents, AppEvent } from './utils/events.js';
|
||||||
import { SettingsContext } from './ui/contexts/SettingsContext.js';
|
|
||||||
|
|
||||||
export function validateDnsResolutionOrder(
|
export function validateDnsResolutionOrder(
|
||||||
order: string | undefined,
|
order: string | undefined,
|
||||||
|
@ -275,18 +273,20 @@ export async function main() {
|
||||||
// Detect and enable Kitty keyboard protocol once at startup
|
// Detect and enable Kitty keyboard protocol once at startup
|
||||||
await detectAndEnableKittyProtocol();
|
await detectAndEnableKittyProtocol();
|
||||||
setWindowTitle(basename(workspaceRoot), settings);
|
setWindowTitle(basename(workspaceRoot), settings);
|
||||||
|
|
||||||
const instance = render(
|
const instance = render(
|
||||||
<React.StrictMode>
|
<MainComponent
|
||||||
<SettingsContext.Provider value={settings}>
|
initialConfig={config}
|
||||||
<AppWrapper
|
settings={settings}
|
||||||
config={config}
|
startupWarnings={startupWarnings}
|
||||||
settings={settings}
|
version={version}
|
||||||
startupWarnings={startupWarnings}
|
workspaceRoot={workspaceRoot}
|
||||||
version={version}
|
extensions={extensions}
|
||||||
/>
|
argv={argv}
|
||||||
</SettingsContext.Provider>
|
/>,
|
||||||
</React.StrictMode>,
|
{
|
||||||
{ exitOnCtrlC: false },
|
exitOnCtrlC: false,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
checkForUpdates()
|
checkForUpdates()
|
||||||
|
|
|
@ -7,12 +7,19 @@
|
||||||
import { render } from 'ink-testing-library';
|
import { render } from 'ink-testing-library';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { KeypressProvider } from '../ui/contexts/KeypressContext.js';
|
import { KeypressProvider } from '../ui/contexts/KeypressContext.js';
|
||||||
|
import { SettingsContext } from '../ui/contexts/SettingsContext.js';
|
||||||
|
import { LoadedSettings } from '../config/settings.js';
|
||||||
|
|
||||||
export const renderWithProviders = (
|
export const renderWithProviders = (
|
||||||
component: React.ReactElement,
|
component: React.ReactElement,
|
||||||
|
settings?: LoadedSettings,
|
||||||
): ReturnType<typeof render> =>
|
): ReturnType<typeof render> =>
|
||||||
render(
|
render(
|
||||||
<KeypressProvider kittyProtocolEnabled={true}>
|
<KeypressProvider kittyProtocolEnabled={true}>
|
||||||
{component}
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: settings!, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
|
{component}
|
||||||
|
</SettingsContext.Provider>
|
||||||
</KeypressProvider>,
|
</KeypressProvider>,
|
||||||
);
|
);
|
||||||
|
|
|
@ -278,6 +278,7 @@ describe('App UI', () => {
|
||||||
user?: Partial<Settings>;
|
user?: Partial<Settings>;
|
||||||
workspace?: Partial<Settings>;
|
workspace?: Partial<Settings>;
|
||||||
} = {},
|
} = {},
|
||||||
|
isTrusted = true,
|
||||||
): LoadedSettings => {
|
): LoadedSettings => {
|
||||||
const systemSettingsFile: SettingsFile = {
|
const systemSettingsFile: SettingsFile = {
|
||||||
path: '/system/settings.json',
|
path: '/system/settings.json',
|
||||||
|
@ -296,6 +297,7 @@ describe('App UI', () => {
|
||||||
userSettingsFile,
|
userSettingsFile,
|
||||||
workspaceSettingsFile,
|
workspaceSettingsFile,
|
||||||
[],
|
[],
|
||||||
|
isTrusted,
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -377,9 +379,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -403,9 +405,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -433,9 +435,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -463,9 +465,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -497,9 +499,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -526,9 +528,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -545,9 +547,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -581,9 +583,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -609,9 +611,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -630,9 +632,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve(); // Wait for any async updates
|
await Promise.resolve(); // Wait for any async updates
|
||||||
|
@ -651,9 +653,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -672,9 +674,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -699,9 +701,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -724,9 +726,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -745,9 +747,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -769,9 +771,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -791,9 +793,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -804,9 +806,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -814,18 +816,21 @@ describe('App UI', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not display Tips component when hideTips is true', async () => {
|
it('should not display Tips component when hideTips is true', async () => {
|
||||||
mockSettings = createMockSettings({
|
mockSettings = createMockSettings(
|
||||||
workspace: {
|
{
|
||||||
hideTips: true,
|
workspace: {
|
||||||
|
hideTips: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -837,9 +842,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -855,9 +860,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -868,9 +873,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -906,9 +911,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -926,9 +931,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -956,9 +961,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -971,9 +976,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -986,9 +991,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
expect(lastFrame()).toMatchSnapshot();
|
expect(lastFrame()).toMatchSnapshot();
|
||||||
|
@ -1006,9 +1011,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
expect(lastFrame()).toMatchSnapshot();
|
expect(lastFrame()).toMatchSnapshot();
|
||||||
|
@ -1036,9 +1041,9 @@ describe('App UI', () => {
|
||||||
const { unmount, rerender } = renderWithProviders(
|
const { unmount, rerender } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -1046,7 +1051,6 @@ describe('App UI', () => {
|
||||||
rerender(
|
rerender(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
|
@ -1078,9 +1082,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -1104,9 +1108,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -1126,9 +1130,9 @@ describe('App UI', () => {
|
||||||
const { unmount } = renderWithProviders(
|
const { unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -1146,9 +1150,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
expect(lastFrame()).toMatchSnapshot();
|
expect(lastFrame()).toMatchSnapshot();
|
||||||
|
@ -1172,9 +1176,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
@ -1194,9 +1198,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -1214,9 +1218,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -1234,9 +1238,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
@ -1483,9 +1487,9 @@ describe('App UI', () => {
|
||||||
const { lastFrame, unmount } = renderWithProviders(
|
const { lastFrame, unmount } = renderWithProviders(
|
||||||
<App
|
<App
|
||||||
config={mockConfig as unknown as ServerConfig}
|
config={mockConfig as unknown as ServerConfig}
|
||||||
settings={mockSettings}
|
|
||||||
version={mockVersion}
|
version={mockVersion}
|
||||||
/>,
|
/>,
|
||||||
|
mockSettings,
|
||||||
);
|
);
|
||||||
currentUnmount = unmount;
|
currentUnmount = unmount;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,14 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useState, useRef } from 'react';
|
import {
|
||||||
|
useCallback,
|
||||||
|
useEffect,
|
||||||
|
useMemo,
|
||||||
|
useState,
|
||||||
|
useRef,
|
||||||
|
useContext,
|
||||||
|
} from 'react';
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
DOMElement,
|
DOMElement,
|
||||||
|
@ -41,7 +48,7 @@ import { ShellConfirmationDialog } from './components/ShellConfirmationDialog.js
|
||||||
import { RadioButtonSelect } from './components/shared/RadioButtonSelect.js';
|
import { RadioButtonSelect } from './components/shared/RadioButtonSelect.js';
|
||||||
import { Colors } from './colors.js';
|
import { Colors } from './colors.js';
|
||||||
import { loadHierarchicalGeminiMemory } from '../config/config.js';
|
import { loadHierarchicalGeminiMemory } from '../config/config.js';
|
||||||
import { LoadedSettings, SettingScope } from '../config/settings.js';
|
import { SettingScope } from '../config/settings.js';
|
||||||
import { Tips } from './components/Tips.js';
|
import { Tips } from './components/Tips.js';
|
||||||
import { ConsolePatcher } from './utils/ConsolePatcher.js';
|
import { ConsolePatcher } from './utils/ConsolePatcher.js';
|
||||||
import { registerCleanup } from '../utils/cleanup.js';
|
import { registerCleanup } from '../utils/cleanup.js';
|
||||||
|
@ -100,6 +107,7 @@ import { useSettingsCommand } from './hooks/useSettingsCommand.js';
|
||||||
import { SettingsDialog } from './components/SettingsDialog.js';
|
import { SettingsDialog } from './components/SettingsDialog.js';
|
||||||
import { setUpdateHandler } from '../utils/handleAutoUpdate.js';
|
import { setUpdateHandler } from '../utils/handleAutoUpdate.js';
|
||||||
import { appEvents, AppEvent } from '../utils/events.js';
|
import { appEvents, AppEvent } from '../utils/events.js';
|
||||||
|
import { SettingsContext } from './contexts/SettingsContext.js';
|
||||||
import { isNarrowWidth } from './utils/isNarrowWidth.js';
|
import { isNarrowWidth } from './utils/isNarrowWidth.js';
|
||||||
|
|
||||||
const CTRL_EXIT_PROMPT_DURATION_MS = 1000;
|
const CTRL_EXIT_PROMPT_DURATION_MS = 1000;
|
||||||
|
@ -108,20 +116,26 @@ const MAX_DISPLAYED_QUEUED_MESSAGES = 3;
|
||||||
|
|
||||||
interface AppProps {
|
interface AppProps {
|
||||||
config: Config;
|
config: Config;
|
||||||
settings: LoadedSettings;
|
|
||||||
startupWarnings?: string[];
|
startupWarnings?: string[];
|
||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AppWrapper = (props: AppProps) => {
|
export const AppWrapper = (props: AppProps) => {
|
||||||
const kittyProtocolStatus = useKittyKeyboardProtocol();
|
const kittyProtocolStatus = useKittyKeyboardProtocol();
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
if (!settingsContext) {
|
||||||
|
// This should not happen as AppWrapper is always rendered within the provider.
|
||||||
|
throw new Error('SettingsContext is not available');
|
||||||
|
}
|
||||||
|
const { settings } = settingsContext;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<KeypressProvider
|
<KeypressProvider
|
||||||
kittyProtocolEnabled={kittyProtocolStatus.enabled}
|
kittyProtocolEnabled={kittyProtocolStatus.enabled}
|
||||||
config={props.config}
|
config={props.config}
|
||||||
>
|
>
|
||||||
<SessionStatsProvider>
|
<SessionStatsProvider>
|
||||||
<VimModeProvider settings={props.settings}>
|
<VimModeProvider settings={settings}>
|
||||||
<App {...props} />
|
<App {...props} />
|
||||||
</VimModeProvider>
|
</VimModeProvider>
|
||||||
</SessionStatsProvider>
|
</SessionStatsProvider>
|
||||||
|
@ -129,13 +143,19 @@ export const AppWrapper = (props: AppProps) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
const App = ({ config, startupWarnings = [], version }: AppProps) => {
|
||||||
const isFocused = useFocus();
|
const isFocused = useFocus();
|
||||||
useBracketedPaste();
|
useBracketedPaste();
|
||||||
const [updateInfo, setUpdateInfo] = useState<UpdateObject | null>(null);
|
const [updateInfo, setUpdateInfo] = useState<UpdateObject | null>(null);
|
||||||
const { stdout } = useStdout();
|
const { stdout } = useStdout();
|
||||||
const nightly = version.includes('nightly');
|
const nightly = version.includes('nightly');
|
||||||
const { history, addItem, clearItems, loadHistory } = useHistory();
|
const { history, addItem, clearItems, loadHistory } = useHistory();
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
if (!settingsContext) {
|
||||||
|
// This should not happen as App is always rendered within the provider.
|
||||||
|
throw new Error('SettingsContext is not available');
|
||||||
|
}
|
||||||
|
const { settings } = settingsContext;
|
||||||
|
|
||||||
const [idePromptAnswered, setIdePromptAnswered] = useState(false);
|
const [idePromptAnswered, setIdePromptAnswered] = useState(false);
|
||||||
const currentIDE = config.getIdeClient().getCurrentIde();
|
const currentIDE = config.getIdeClient().getCurrentIde();
|
||||||
|
@ -262,7 +282,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
openThemeDialog,
|
openThemeDialog,
|
||||||
handleThemeSelect,
|
handleThemeSelect,
|
||||||
handleThemeHighlight,
|
handleThemeHighlight,
|
||||||
} = useThemeCommand(settings, setThemeError, addItem);
|
} = useThemeCommand(setThemeError, addItem);
|
||||||
|
|
||||||
const { isSettingsDialogOpen, openSettingsDialog, closeSettingsDialog } =
|
const { isSettingsDialogOpen, openSettingsDialog, closeSettingsDialog } =
|
||||||
useSettingsCommand();
|
useSettingsCommand();
|
||||||
|
@ -308,7 +328,7 @@ const App = ({ config, settings, startupWarnings = [], version }: AppProps) => {
|
||||||
openEditorDialog,
|
openEditorDialog,
|
||||||
handleEditorSelect,
|
handleEditorSelect,
|
||||||
exitEditorDialog,
|
exitEditorDialog,
|
||||||
} = useEditorSettings(settings, setEditorError, addItem);
|
} = useEditorSettings(setEditorError, addItem);
|
||||||
|
|
||||||
const toggleCorgiMode = useCallback(() => {
|
const toggleCorgiMode = useCallback(() => {
|
||||||
setCorgiMode((prev) => !prev);
|
setCorgiMode((prev) => !prev);
|
||||||
|
|
|
@ -0,0 +1,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>
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,24 @@
|
||||||
|
/**
|
||||||
|
* @license
|
||||||
|
* Copyright 2025 Google LLC
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createContext, useContext } from 'react';
|
||||||
|
import { LoadedSettings } from '../../config/settings.js';
|
||||||
|
|
||||||
|
export interface SettingsContextType {
|
||||||
|
settings: LoadedSettings;
|
||||||
|
recomputeSettings: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This context is initialized in gemini.tsx with the loaded settings.
|
||||||
|
export const SettingsContext = createContext<SettingsContextType | null>(null);
|
||||||
|
|
||||||
|
export function useSettings(): LoadedSettings {
|
||||||
|
const context = useContext(SettingsContext);
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('useSettings must be used within a SettingsProvider');
|
||||||
|
}
|
||||||
|
return context.settings;
|
||||||
|
}
|
|
@ -12,6 +12,7 @@ import {
|
||||||
useState,
|
useState,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { LoadedSettings, SettingScope } from '../../config/settings.js';
|
import { LoadedSettings, SettingScope } from '../../config/settings.js';
|
||||||
|
import { SettingsContext } from './SettingsContext.js';
|
||||||
|
|
||||||
export type VimMode = 'NORMAL' | 'INSERT';
|
export type VimMode = 'NORMAL' | 'INSERT';
|
||||||
|
|
||||||
|
@ -26,11 +27,13 @@ const VimModeContext = createContext<VimModeContextType | undefined>(undefined);
|
||||||
|
|
||||||
export const VimModeProvider = ({
|
export const VimModeProvider = ({
|
||||||
children,
|
children,
|
||||||
settings,
|
settings: initialSettings,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
settings: LoadedSettings;
|
settings: LoadedSettings;
|
||||||
}) => {
|
}) => {
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
const settings = settingsContext?.settings || initialSettings;
|
||||||
const initialVimEnabled = settings.merged.vimMode ?? false;
|
const initialVimEnabled = settings.merged.vimMode ?? false;
|
||||||
const [vimEnabled, setVimEnabled] = useState(initialVimEnabled);
|
const [vimEnabled, setVimEnabled] = useState(initialVimEnabled);
|
||||||
const [vimMode, setVimMode] = useState<VimMode>(
|
const [vimMode, setVimMode] = useState<VimMode>(
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect, useContext } from 'react';
|
||||||
import { LoadedSettings, SettingScope } from '../../config/settings.js';
|
import { LoadedSettings, SettingScope } from '../../config/settings.js';
|
||||||
import {
|
import {
|
||||||
AuthType,
|
AuthType,
|
||||||
|
@ -13,6 +13,7 @@ import {
|
||||||
getErrorMessage,
|
getErrorMessage,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
import { runExitCleanup } from '../../utils/cleanup.js';
|
import { runExitCleanup } from '../../utils/cleanup.js';
|
||||||
|
import { SettingsContext } from '../contexts/SettingsContext.js';
|
||||||
|
|
||||||
export const useAuthCommand = (
|
export const useAuthCommand = (
|
||||||
settings: LoadedSettings,
|
settings: LoadedSettings,
|
||||||
|
@ -22,6 +23,7 @@ export const useAuthCommand = (
|
||||||
const [isAuthDialogOpen, setIsAuthDialogOpen] = useState(
|
const [isAuthDialogOpen, setIsAuthDialogOpen] = useState(
|
||||||
settings.merged.selectedAuthType === undefined,
|
settings.merged.selectedAuthType === undefined,
|
||||||
);
|
);
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
|
||||||
const openAuthDialog = useCallback(() => {
|
const openAuthDialog = useCallback(() => {
|
||||||
setIsAuthDialogOpen(true);
|
setIsAuthDialogOpen(true);
|
||||||
|
@ -56,7 +58,7 @@ export const useAuthCommand = (
|
||||||
if (authType) {
|
if (authType) {
|
||||||
await clearCachedCredentialFile();
|
await clearCachedCredentialFile();
|
||||||
|
|
||||||
settings.setValue(scope, 'selectedAuthType', authType);
|
settingsContext?.settings.setValue(scope, 'selectedAuthType', authType);
|
||||||
if (
|
if (
|
||||||
authType === AuthType.LOGIN_WITH_GOOGLE &&
|
authType === AuthType.LOGIN_WITH_GOOGLE &&
|
||||||
config.isBrowserLaunchSuppressed()
|
config.isBrowserLaunchSuppressed()
|
||||||
|
@ -75,7 +77,7 @@ Logging in with Google... Please restart Gemini CLI to continue.
|
||||||
setIsAuthDialogOpen(false);
|
setIsAuthDialogOpen(false);
|
||||||
setAuthError(null);
|
setAuthError(null);
|
||||||
},
|
},
|
||||||
[settings, setAuthError, config],
|
[settingsContext, setAuthError, config],
|
||||||
);
|
);
|
||||||
|
|
||||||
const cancelAuthentication = useCallback(() => {
|
const cancelAuthentication = useCallback(() => {
|
||||||
|
|
|
@ -23,6 +23,8 @@ import {
|
||||||
checkHasEditorType,
|
checkHasEditorType,
|
||||||
allowEditorTypeInSandbox,
|
allowEditorTypeInSandbox,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
|
import { SettingsContext } from '../contexts/SettingsContext.js';
|
||||||
|
import { type ReactNode } from 'react';
|
||||||
|
|
||||||
vi.mock('@google/gemini-cli-core', async () => {
|
vi.mock('@google/gemini-cli-core', async () => {
|
||||||
const actual = await vi.importActual('@google/gemini-cli-core');
|
const actual = await vi.importActual('@google/gemini-cli-core');
|
||||||
|
@ -43,13 +45,23 @@ describe('useEditorSettings', () => {
|
||||||
(item: Omit<HistoryItem, 'id'>, timestamp: number) => void
|
(item: Omit<HistoryItem, 'id'>, timestamp: number) => void
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
const wrapper = ({ children }: { children: ReactNode }) => (
|
||||||
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockLoadedSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</SettingsContext.Provider>
|
||||||
|
);
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.resetAllMocks();
|
vi.resetAllMocks();
|
||||||
|
mockLoadedSettings = new LoadedSettings(
|
||||||
mockLoadedSettings = {
|
{ path: '', settings: {} },
|
||||||
setValue: vi.fn(),
|
{ path: '', settings: {} },
|
||||||
} as unknown as LoadedSettings;
|
{ path: '', settings: {} },
|
||||||
|
[],
|
||||||
|
);
|
||||||
|
mockLoadedSettings.setValue = vi.fn();
|
||||||
mockSetEditorError = vi.fn();
|
mockSetEditorError = vi.fn();
|
||||||
mockAddItem = vi.fn();
|
mockAddItem = vi.fn();
|
||||||
|
|
||||||
|
@ -63,16 +75,18 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should initialize with dialog closed', () => {
|
it('should initialize with dialog closed', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(result.current.isEditorDialogOpen).toBe(false);
|
expect(result.current.isEditorDialogOpen).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open editor dialog when openEditorDialog is called', () => {
|
it('should open editor dialog when openEditorDialog is called', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
|
@ -83,8 +97,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close editor dialog when exitEditorDialog is called', () => {
|
it('should close editor dialog when exitEditorDialog is called', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
act(() => {
|
act(() => {
|
||||||
result.current.openEditorDialog();
|
result.current.openEditorDialog();
|
||||||
|
@ -94,8 +109,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle editor selection successfully', () => {
|
it('should handle editor selection successfully', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorType: EditorType = 'vscode';
|
const editorType: EditorType = 'vscode';
|
||||||
|
@ -125,8 +141,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle clearing editor preference (undefined editor)', () => {
|
it('should handle clearing editor preference (undefined editor)', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
const scope = SettingScope.Workspace;
|
const scope = SettingScope.Workspace;
|
||||||
|
@ -155,8 +172,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle different editor types', () => {
|
it('should handle different editor types', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorTypes: EditorType[] = ['cursor', 'windsurf', 'vim'];
|
const editorTypes: EditorType[] = ['cursor', 'windsurf', 'vim'];
|
||||||
|
@ -184,8 +202,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle different setting scopes', () => {
|
it('should handle different setting scopes', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
const editorType: EditorType = 'vscode';
|
const editorType: EditorType = 'vscode';
|
||||||
|
@ -213,8 +232,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not set preference for unavailable editors', () => {
|
it('should not set preference for unavailable editors', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
mockCheckHasEditorType.mockReturnValue(false);
|
mockCheckHasEditorType.mockReturnValue(false);
|
||||||
|
@ -233,8 +253,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not set preference for editors not allowed in sandbox', () => {
|
it('should not set preference for editors not allowed in sandbox', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
mockAllowEditorTypeInSandbox.mockReturnValue(false);
|
mockAllowEditorTypeInSandbox.mockReturnValue(false);
|
||||||
|
@ -253,8 +274,9 @@ describe('useEditorSettings', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle errors during editor selection', () => {
|
it('should handle errors during editor selection', () => {
|
||||||
const { result } = renderHook(() =>
|
const { result } = renderHook(
|
||||||
useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem),
|
() => useEditorSettings(mockSetEditorError, mockAddItem),
|
||||||
|
{ wrapper },
|
||||||
);
|
);
|
||||||
|
|
||||||
const errorMessage = 'Failed to save settings';
|
const errorMessage = 'Failed to save settings';
|
|
@ -4,14 +4,15 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useCallback } from 'react';
|
import { useState, useCallback, useContext } from 'react';
|
||||||
import { LoadedSettings, SettingScope } from '../../config/settings.js';
|
import { SettingScope } from '../../config/settings.js';
|
||||||
import { type HistoryItem, MessageType } from '../types.js';
|
import { type HistoryItem, MessageType } from '../types.js';
|
||||||
import {
|
import {
|
||||||
allowEditorTypeInSandbox,
|
allowEditorTypeInSandbox,
|
||||||
checkHasEditorType,
|
checkHasEditorType,
|
||||||
EditorType,
|
EditorType,
|
||||||
} from '@google/gemini-cli-core';
|
} from '@google/gemini-cli-core';
|
||||||
|
import { SettingsContext } from '../contexts/SettingsContext.js';
|
||||||
|
|
||||||
interface UseEditorSettingsReturn {
|
interface UseEditorSettingsReturn {
|
||||||
isEditorDialogOpen: boolean;
|
isEditorDialogOpen: boolean;
|
||||||
|
@ -24,11 +25,11 @@ interface UseEditorSettingsReturn {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useEditorSettings = (
|
export const useEditorSettings = (
|
||||||
loadedSettings: LoadedSettings,
|
|
||||||
setEditorError: (error: string | null) => void,
|
setEditorError: (error: string | null) => void,
|
||||||
addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
|
addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
|
||||||
): UseEditorSettingsReturn => {
|
): UseEditorSettingsReturn => {
|
||||||
const [isEditorDialogOpen, setIsEditorDialogOpen] = useState(false);
|
const [isEditorDialogOpen, setIsEditorDialogOpen] = useState(false);
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
|
||||||
const openEditorDialog = useCallback(() => {
|
const openEditorDialog = useCallback(() => {
|
||||||
setIsEditorDialogOpen(true);
|
setIsEditorDialogOpen(true);
|
||||||
|
@ -45,7 +46,11 @@ export const useEditorSettings = (
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loadedSettings.setValue(scope, 'preferredEditor', editorType);
|
settingsContext?.settings.setValue(
|
||||||
|
scope,
|
||||||
|
'preferredEditor',
|
||||||
|
editorType,
|
||||||
|
);
|
||||||
addItem(
|
addItem(
|
||||||
{
|
{
|
||||||
type: MessageType.INFO,
|
type: MessageType.INFO,
|
||||||
|
@ -59,7 +64,7 @@ export const useEditorSettings = (
|
||||||
setEditorError(`Failed to set editor preference: ${error}`);
|
setEditorError(`Failed to set editor preference: ${error}`);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[loadedSettings, setEditorError, addItem],
|
[settingsContext, setEditorError, addItem],
|
||||||
);
|
);
|
||||||
|
|
||||||
const exitEditorDialog = useCallback(() => {
|
const exitEditorDialog = useCallback(() => {
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect, useContext } from 'react';
|
||||||
import { Settings, LoadedSettings } from '../../config/settings.js';
|
import { Settings, LoadedSettings } from '../../config/settings.js';
|
||||||
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
|
import { FolderTrustChoice } from '../components/FolderTrustDialog.js';
|
||||||
import {
|
import {
|
||||||
|
@ -13,6 +13,7 @@ import {
|
||||||
isWorkspaceTrusted,
|
isWorkspaceTrusted,
|
||||||
} from '../../config/trustedFolders.js';
|
} from '../../config/trustedFolders.js';
|
||||||
import * as process from 'process';
|
import * as process from 'process';
|
||||||
|
import { SettingsContext } from '../contexts/SettingsContext.js';
|
||||||
|
|
||||||
export const useFolderTrust = (
|
export const useFolderTrust = (
|
||||||
settings: LoadedSettings,
|
settings: LoadedSettings,
|
||||||
|
@ -20,6 +21,7 @@ export const useFolderTrust = (
|
||||||
) => {
|
) => {
|
||||||
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
|
const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined);
|
||||||
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
|
const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false);
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
|
||||||
const { folderTrust, folderTrustFeature } = settings.merged;
|
const { folderTrust, folderTrustFeature } = settings.merged;
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -60,8 +62,9 @@ export const useFolderTrust = (
|
||||||
setIsTrusted(trusted);
|
setIsTrusted(trusted);
|
||||||
setIsFolderTrustDialogOpen(false);
|
setIsFolderTrustDialogOpen(false);
|
||||||
onTrustChange(trusted);
|
onTrustChange(trusted);
|
||||||
|
settingsContext?.recomputeSettings();
|
||||||
},
|
},
|
||||||
[onTrustChange, folderTrust, folderTrustFeature],
|
[onTrustChange, folderTrust, folderTrustFeature, settingsContext],
|
||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { useState, useCallback, useEffect } from 'react';
|
import { useState, useCallback, useEffect, useContext } from 'react';
|
||||||
import { themeManager } from '../themes/theme-manager.js';
|
import { themeManager } from '../themes/theme-manager.js';
|
||||||
import { LoadedSettings, SettingScope } from '../../config/settings.js'; // Import LoadedSettings, AppSettings, MergedSetting
|
import { HistoryItem, MessageType } from '../types.js';
|
||||||
import { type HistoryItem, MessageType } from '../types.js';
|
import { SettingScope } from '../../config/settings.js';
|
||||||
|
import { SettingsContext } from '../contexts/SettingsContext.js';
|
||||||
import process from 'node:process';
|
import process from 'node:process';
|
||||||
|
|
||||||
interface UseThemeCommandReturn {
|
interface UseThemeCommandReturn {
|
||||||
|
@ -21,11 +22,12 @@ interface UseThemeCommandReturn {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useThemeCommand = (
|
export const useThemeCommand = (
|
||||||
loadedSettings: LoadedSettings,
|
|
||||||
setThemeError: (error: string | null) => void,
|
setThemeError: (error: string | null) => void,
|
||||||
addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
|
addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void,
|
||||||
): UseThemeCommandReturn => {
|
): UseThemeCommandReturn => {
|
||||||
const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false);
|
const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false);
|
||||||
|
const settingsContext = useContext(SettingsContext);
|
||||||
|
const loadedSettings = settingsContext!.settings;
|
||||||
|
|
||||||
// Check for invalid theme configuration on startup
|
// Check for invalid theme configuration on startup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
|
@ -30,7 +30,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
|
|
||||||
it('renders nothing for empty text', () => {
|
it('renders nothing for empty text', () => {
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text="" />
|
<MarkdownDisplay {...baseProps} text="" />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -40,7 +42,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
it('renders a simple paragraph', () => {
|
it('renders a simple paragraph', () => {
|
||||||
const text = 'Hello, world.';
|
const text = 'Hello, world.';
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -55,7 +59,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
#### Header 4
|
#### Header 4
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -65,7 +71,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
it('renders a fenced code block with a language', () => {
|
it('renders a fenced code block with a language', () => {
|
||||||
const text = '```javascript\nconst x = 1;\nconsole.log(x);\n```';
|
const text = '```javascript\nconst x = 1;\nconsole.log(x);\n```';
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -75,7 +83,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
it('renders a fenced code block without a language', () => {
|
it('renders a fenced code block without a language', () => {
|
||||||
const text = '```\nplain text\n```';
|
const text = '```\nplain text\n```';
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -85,7 +95,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
it('handles unclosed (pending) code blocks', () => {
|
it('handles unclosed (pending) code blocks', () => {
|
||||||
const text = '```typescript\nlet y = 2;';
|
const text = '```typescript\nlet y = 2;';
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} isPending={true} />
|
<MarkdownDisplay {...baseProps} text={text} isPending={true} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -99,7 +111,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
+ item C
|
+ item C
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -113,7 +127,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
* Level 3
|
* Level 3
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -126,7 +142,9 @@ describe('<MarkdownDisplay />', () => {
|
||||||
2. Second item
|
2. Second item
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -142,7 +160,9 @@ World
|
||||||
Test
|
Test
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -157,7 +177,9 @@ Test
|
||||||
| Cell 3 | Cell 4 |
|
| Cell 3 | Cell 4 |
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -168,10 +190,12 @@ Test
|
||||||
const text = `
|
const text = `
|
||||||
Some text before.
|
Some text before.
|
||||||
| A | B |
|
| A | B |
|
||||||
|---|
|
|---|
|
||||||
| 1 | 2 |`;
|
| 1 | 2 |`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -183,7 +207,9 @@ Some text before.
|
||||||
|
|
||||||
Paragraph 2.`;
|
Paragraph 2.`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -206,7 +232,9 @@ some code
|
||||||
Another paragraph.
|
Another paragraph.
|
||||||
`;
|
`;
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -223,7 +251,9 @@ Another paragraph.
|
||||||
);
|
);
|
||||||
|
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={settings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
@ -234,7 +264,9 @@ Another paragraph.
|
||||||
it('shows line numbers in code blocks by default', () => {
|
it('shows line numbers in code blocks by default', () => {
|
||||||
const text = '```javascript\nconst x = 1;\n```';
|
const text = '```javascript\nconst x = 1;\n```';
|
||||||
const { lastFrame } = render(
|
const { lastFrame } = render(
|
||||||
<SettingsContext.Provider value={mockSettings}>
|
<SettingsContext.Provider
|
||||||
|
value={{ settings: mockSettings, recomputeSettings: () => {} }}
|
||||||
|
>
|
||||||
<MarkdownDisplay {...baseProps} text={text} />
|
<MarkdownDisplay {...baseProps} text={text} />
|
||||||
</SettingsContext.Provider>,
|
</SettingsContext.Provider>,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in New Issue