Skip to content

Commit

Permalink
feat: binary configuration setting
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Oct 26, 2023
1 parent 09a9732 commit 2cd4e6c
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,40 @@ export const GlobalSettings = () => {
[_setShouldAppendServerPath]
);

const [isOverridingBinaryPaths, _setIsOverridingBinaryPaths] = useState<boolean>(
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<string>(
electronStore.get('appConfig.binaryPaths.kubectl') ?? ''
);

const setKubectlBinaryPath = useCallback(
(value: string) => {
_setKubectlBinaryPath(value);
electronStore.set('appConfig.binaryPaths.kubectl', value);
},
[_setKubectlBinaryPath]
);

const [helmBinaryPath, _setHelmBinaryPath] = useState<string>(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();
Expand Down Expand Up @@ -159,6 +193,23 @@ export const GlobalSettings = () => {
Append Server Path to Kubectl Proxy
</Checkbox>
</S.Div>

<S.Div>
<S.Span>Binary Configuration</S.Span>
<Checkbox checked={isOverridingBinaryPaths} onChange={e => setIsOverridingBinaryPaths(e.target.checked)}>
Override binary paths
</Checkbox>
{isOverridingBinaryPaths && (
<>
<Form.Item label="kubectl path">
<Input value={kubectlBinaryPath} onChange={e => setKubectlBinaryPath(e.target.value)} />
</Form.Item>
<Form.Item label="helm path">
<Input value={helmBinaryPath} onChange={e => setHelmBinaryPath(e.target.value)} />
</Form.Item>
</>
)}
</S.Div>
</div>

<div style={{width: '45%'}}>
Expand Down
11 changes: 11 additions & 0 deletions src/shared/constants/electronStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
12 changes: 12 additions & 0 deletions src/shared/utils/commands/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandResult> {
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<CommandResult>(resolve => {
const cb = (_event: unknown, arg: CommandResult) => {
if (arg.commandId !== options.commandId) return;
Expand Down

0 comments on commit 2cd4e6c

Please sign in to comment.