From 2cd4e6c3b42f62ca8d7c1a8645db802a51105c4c Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Thu, 26 Oct 2023 13:07:22 +0300 Subject: [PATCH] feat: binary configuration setting --- .../GlobalSettings/GlobalSettings.tsx | 51 +++++++++++++++++++ src/shared/constants/electronStore.ts | 11 ++++ src/shared/utils/commands/execute.ts | 12 +++++ 3 files changed, 74 insertions(+) diff --git a/src/components/organisms/SettingsPane/GlobalSettings/GlobalSettings.tsx b/src/components/organisms/SettingsPane/GlobalSettings/GlobalSettings.tsx index 74039eb4ef..cc8d66db9f 100644 --- a/src/components/organisms/SettingsPane/GlobalSettings/GlobalSettings.tsx +++ b/src/components/organisms/SettingsPane/GlobalSettings/GlobalSettings.tsx @@ -48,6 +48,40 @@ export const GlobalSettings = () => { [_setShouldAppendServerPath] ); + const [isOverridingBinaryPaths, _setIsOverridingBinaryPaths] = useState( + Boolean(electronStore.get('appConfig.binaryPaths')) ?? false + ); + + const setIsOverridingBinaryPaths = useCallback( + (value: boolean) => { + _setIsOverridingBinaryPaths(value); + electronStore.set('appConfig.binaryPaths', value === false ? null : {}); + }, + [_setIsOverridingBinaryPaths] + ); + + const [kubectlBinaryPath, _setKubectlBinaryPath] = useState( + electronStore.get('appConfig.binaryPaths.kubectl') ?? '' + ); + + const setKubectlBinaryPath = useCallback( + (value: string) => { + _setKubectlBinaryPath(value); + electronStore.set('appConfig.binaryPaths.kubectl', value); + }, + [_setKubectlBinaryPath] + ); + + const [helmBinaryPath, _setHelmBinaryPath] = useState(electronStore.get('appConfig.binaryPaths.helm') ?? ''); + + const setHelmBinaryPath = useCallback( + (value: string) => { + _setHelmBinaryPath(value); + electronStore.set('appConfig.binaryPaths.helm', value); + }, + [_setHelmBinaryPath] + ); + const [currentProjectsRootPath, setCurrentProjectsRootPath] = useState(projectsRootPath); const [settingsForm] = useForm(); @@ -159,6 +193,23 @@ export const GlobalSettings = () => { Append Server Path to Kubectl Proxy + + + Binary Configuration + setIsOverridingBinaryPaths(e.target.checked)}> + Override binary paths + + {isOverridingBinaryPaths && ( + <> + + setKubectlBinaryPath(e.target.value)} /> + + + setHelmBinaryPath(e.target.value)} /> + + + )} +
diff --git a/src/shared/constants/electronStore.ts b/src/shared/constants/electronStore.ts index d6ab6b75fb..787d234688 100644 --- a/src/shared/constants/electronStore.ts +++ b/src/shared/constants/electronStore.ts @@ -26,6 +26,17 @@ export const electronStoreSchema = { appConfig: { type: 'object', properties: { + binaryPaths: { + type: ['object', 'null'], + properties: { + kubectl: { + type: 'string', + }, + helm: { + type: 'string', + }, + }, + }, userApiKeys: { type: 'object', properties: { diff --git a/src/shared/utils/commands/execute.ts b/src/shared/utils/commands/execute.ts index 3dd8d1eb2d..8c73556a31 100644 --- a/src/shared/utils/commands/execute.ts +++ b/src/shared/utils/commands/execute.ts @@ -7,10 +7,22 @@ import {CommandOptions, CommandResult} from '@shared/models/commands'; import {isDefined} from '@shared/utils/filter'; import {ensureRendererThread} from '@shared/utils/thread'; +import electronStore from '../electronStore'; + export function runCommandInMainThread(options: CommandOptions): Promise { ensureRendererThread(); log.info('sending command to main thread', options); + const binaryPaths = electronStore.get('appConfig.binaryPaths'); + if (binaryPaths) { + if (typeof binaryPaths.kubectl === 'string' && options.cmd.startsWith('kubectl')) { + options.cmd = options.cmd.replace('kubectl', binaryPaths.kubectl); + } + if (typeof binaryPaths.helm === 'string' && options.cmd.startsWith('helm')) { + options.cmd = options.cmd.replace('helm', binaryPaths.helm); + } + } + return new Promise(resolve => { const cb = (_event: unknown, arg: CommandResult) => { if (arg.commandId !== options.commandId) return;