diff options
Diffstat (limited to 'packages/cli/src/ui/hooks')
| -rw-r--r-- | packages/cli/src/ui/hooks/useAuthCommand.ts | 8 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useEditorSettings.test.ts (renamed from packages/cli/src/ui/hooks/useEditorSettings.test.tsx) | 72 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useEditorSettings.ts | 15 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useFolderTrust.ts | 7 | ||||
| -rw-r--r-- | packages/cli/src/ui/hooks/useThemeCommand.ts | 10 |
5 files changed, 39 insertions, 73 deletions
diff --git a/packages/cli/src/ui/hooks/useAuthCommand.ts b/packages/cli/src/ui/hooks/useAuthCommand.ts index b92fe604..e57a11af 100644 --- a/packages/cli/src/ui/hooks/useAuthCommand.ts +++ b/packages/cli/src/ui/hooks/useAuthCommand.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { useState, useCallback, useEffect, useContext } from 'react'; +import { useState, useCallback, useEffect } from 'react'; import { LoadedSettings, SettingScope } from '../../config/settings.js'; import { AuthType, @@ -13,7 +13,6 @@ import { getErrorMessage, } from '@google/gemini-cli-core'; import { runExitCleanup } from '../../utils/cleanup.js'; -import { SettingsContext } from '../contexts/SettingsContext.js'; export const useAuthCommand = ( settings: LoadedSettings, @@ -23,7 +22,6 @@ export const useAuthCommand = ( const [isAuthDialogOpen, setIsAuthDialogOpen] = useState( settings.merged.selectedAuthType === undefined, ); - const settingsContext = useContext(SettingsContext); const openAuthDialog = useCallback(() => { setIsAuthDialogOpen(true); @@ -58,7 +56,7 @@ export const useAuthCommand = ( if (authType) { await clearCachedCredentialFile(); - settingsContext?.settings.setValue(scope, 'selectedAuthType', authType); + settings.setValue(scope, 'selectedAuthType', authType); if ( authType === AuthType.LOGIN_WITH_GOOGLE && config.isBrowserLaunchSuppressed() @@ -77,7 +75,7 @@ Logging in with Google... Please restart Gemini CLI to continue. setIsAuthDialogOpen(false); setAuthError(null); }, - [settingsContext, setAuthError, config], + [settings, setAuthError, config], ); const cancelAuthentication = useCallback(() => { diff --git a/packages/cli/src/ui/hooks/useEditorSettings.test.tsx b/packages/cli/src/ui/hooks/useEditorSettings.test.ts index f1d65056..7b056c2a 100644 --- a/packages/cli/src/ui/hooks/useEditorSettings.test.tsx +++ b/packages/cli/src/ui/hooks/useEditorSettings.test.ts @@ -23,8 +23,6 @@ import { checkHasEditorType, allowEditorTypeInSandbox, } from '@google/gemini-cli-core'; -import { SettingsContext } from '../contexts/SettingsContext.js'; -import { type ReactNode } from 'react'; vi.mock('@google/gemini-cli-core', async () => { const actual = await vi.importActual('@google/gemini-cli-core'); @@ -45,23 +43,13 @@ describe('useEditorSettings', () => { (item: Omit<HistoryItem, 'id'>, timestamp: number) => void >; - const wrapper = ({ children }: { children: ReactNode }) => ( - <SettingsContext.Provider - value={{ settings: mockLoadedSettings, recomputeSettings: () => {} }} - > - {children} - </SettingsContext.Provider> - ); - beforeEach(() => { vi.resetAllMocks(); - mockLoadedSettings = new LoadedSettings( - { path: '', settings: {} }, - { path: '', settings: {} }, - { path: '', settings: {} }, - [], - ); - mockLoadedSettings.setValue = vi.fn(); + + mockLoadedSettings = { + setValue: vi.fn(), + } as unknown as LoadedSettings; + mockSetEditorError = vi.fn(); mockAddItem = vi.fn(); @@ -75,18 +63,16 @@ describe('useEditorSettings', () => { }); it('should initialize with dialog closed', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); expect(result.current.isEditorDialogOpen).toBe(false); }); it('should open editor dialog when openEditorDialog is called', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); act(() => { @@ -97,9 +83,8 @@ describe('useEditorSettings', () => { }); it('should close editor dialog when exitEditorDialog is called', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); act(() => { result.current.openEditorDialog(); @@ -109,9 +94,8 @@ describe('useEditorSettings', () => { }); it('should handle editor selection successfully', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); const editorType: EditorType = 'vscode'; @@ -141,9 +125,8 @@ describe('useEditorSettings', () => { }); it('should handle clearing editor preference (undefined editor)', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); const scope = SettingScope.Workspace; @@ -172,9 +155,8 @@ describe('useEditorSettings', () => { }); it('should handle different editor types', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); const editorTypes: EditorType[] = ['cursor', 'windsurf', 'vim']; @@ -202,9 +184,8 @@ describe('useEditorSettings', () => { }); it('should handle different setting scopes', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); const editorType: EditorType = 'vscode'; @@ -232,9 +213,8 @@ describe('useEditorSettings', () => { }); it('should not set preference for unavailable editors', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); mockCheckHasEditorType.mockReturnValue(false); @@ -253,9 +233,8 @@ describe('useEditorSettings', () => { }); it('should not set preference for editors not allowed in sandbox', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); mockAllowEditorTypeInSandbox.mockReturnValue(false); @@ -274,9 +253,8 @@ describe('useEditorSettings', () => { }); it('should handle errors during editor selection', () => { - const { result } = renderHook( - () => useEditorSettings(mockSetEditorError, mockAddItem), - { wrapper }, + const { result } = renderHook(() => + useEditorSettings(mockLoadedSettings, mockSetEditorError, mockAddItem), ); const errorMessage = 'Failed to save settings'; diff --git a/packages/cli/src/ui/hooks/useEditorSettings.ts b/packages/cli/src/ui/hooks/useEditorSettings.ts index bd6f72bb..60c16798 100644 --- a/packages/cli/src/ui/hooks/useEditorSettings.ts +++ b/packages/cli/src/ui/hooks/useEditorSettings.ts @@ -4,15 +4,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { useState, useCallback, useContext } from 'react'; -import { SettingScope } from '../../config/settings.js'; +import { useState, useCallback } from 'react'; +import { LoadedSettings, SettingScope } from '../../config/settings.js'; import { type HistoryItem, MessageType } from '../types.js'; import { allowEditorTypeInSandbox, checkHasEditorType, EditorType, } from '@google/gemini-cli-core'; -import { SettingsContext } from '../contexts/SettingsContext.js'; interface UseEditorSettingsReturn { isEditorDialogOpen: boolean; @@ -25,11 +24,11 @@ interface UseEditorSettingsReturn { } export const useEditorSettings = ( + loadedSettings: LoadedSettings, setEditorError: (error: string | null) => void, addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void, ): UseEditorSettingsReturn => { const [isEditorDialogOpen, setIsEditorDialogOpen] = useState(false); - const settingsContext = useContext(SettingsContext); const openEditorDialog = useCallback(() => { setIsEditorDialogOpen(true); @@ -46,11 +45,7 @@ export const useEditorSettings = ( } try { - settingsContext?.settings.setValue( - scope, - 'preferredEditor', - editorType, - ); + loadedSettings.setValue(scope, 'preferredEditor', editorType); addItem( { type: MessageType.INFO, @@ -64,7 +59,7 @@ export const useEditorSettings = ( setEditorError(`Failed to set editor preference: ${error}`); } }, - [settingsContext, setEditorError, addItem], + [loadedSettings, setEditorError, addItem], ); const exitEditorDialog = useCallback(() => { diff --git a/packages/cli/src/ui/hooks/useFolderTrust.ts b/packages/cli/src/ui/hooks/useFolderTrust.ts index 560a2260..28b82b30 100644 --- a/packages/cli/src/ui/hooks/useFolderTrust.ts +++ b/packages/cli/src/ui/hooks/useFolderTrust.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { useState, useCallback, useEffect, useContext } from 'react'; +import { useState, useCallback, useEffect } from 'react'; import { Settings, LoadedSettings } from '../../config/settings.js'; import { FolderTrustChoice } from '../components/FolderTrustDialog.js'; import { @@ -13,7 +13,6 @@ import { isWorkspaceTrusted, } from '../../config/trustedFolders.js'; import * as process from 'process'; -import { SettingsContext } from '../contexts/SettingsContext.js'; export const useFolderTrust = ( settings: LoadedSettings, @@ -21,7 +20,6 @@ export const useFolderTrust = ( ) => { const [isTrusted, setIsTrusted] = useState<boolean | undefined>(undefined); const [isFolderTrustDialogOpen, setIsFolderTrustDialogOpen] = useState(false); - const settingsContext = useContext(SettingsContext); const { folderTrust, folderTrustFeature } = settings.merged; useEffect(() => { @@ -62,9 +60,8 @@ export const useFolderTrust = ( setIsTrusted(trusted); setIsFolderTrustDialogOpen(false); onTrustChange(trusted); - settingsContext?.recomputeSettings(); }, - [onTrustChange, folderTrust, folderTrustFeature, settingsContext], + [onTrustChange, folderTrust, folderTrustFeature], ); return { diff --git a/packages/cli/src/ui/hooks/useThemeCommand.ts b/packages/cli/src/ui/hooks/useThemeCommand.ts index 06d1c5b1..cf881f53 100644 --- a/packages/cli/src/ui/hooks/useThemeCommand.ts +++ b/packages/cli/src/ui/hooks/useThemeCommand.ts @@ -4,11 +4,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { useState, useCallback, useEffect, useContext } from 'react'; +import { useState, useCallback, useEffect } from 'react'; import { themeManager } from '../themes/theme-manager.js'; -import { HistoryItem, MessageType } from '../types.js'; -import { SettingScope } from '../../config/settings.js'; -import { SettingsContext } from '../contexts/SettingsContext.js'; +import { LoadedSettings, SettingScope } from '../../config/settings.js'; // Import LoadedSettings, AppSettings, MergedSetting +import { type HistoryItem, MessageType } from '../types.js'; import process from 'node:process'; interface UseThemeCommandReturn { @@ -22,12 +21,11 @@ interface UseThemeCommandReturn { } export const useThemeCommand = ( + loadedSettings: LoadedSettings, setThemeError: (error: string | null) => void, addItem: (item: Omit<HistoryItem, 'id'>, timestamp: number) => void, ): UseThemeCommandReturn => { const [isThemeDialogOpen, setIsThemeDialogOpen] = useState(false); - const settingsContext = useContext(SettingsContext); - const loadedSettings = settingsContext!.settings; // Check for invalid theme configuration on startup useEffect(() => { |
