Skip to content

Commit 2b02594

Browse files
committed
Use the new save selector for the keylog file picker
1 parent 1ddd3d8 commit 2b02594

File tree

3 files changed

+67
-21
lines changed

3 files changed

+67
-21
lines changed

src/components/settings/proxy-settings-card.tsx

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as _ from 'lodash';
22
import * as React from 'react';
3-
import { observable, action, computed } from 'mobx';
3+
import { observable, action, computed, runInAction } from 'mobx';
44
import { observer, inject } from "mobx-react";
55

66
import { styled } from '../../styles';
@@ -11,11 +11,14 @@ import { isValidPortConfiguration, ProxyStore } from '../../model/proxy-store';
1111
import { isValidHostname } from '../../model/network';
1212
import {
1313
serverVersion,
14+
desktopVersion,
1415
versionSatisfies,
1516
INITIAL_HTTP2_RANGE,
1617
TLS_PASSTHROUGH_SUPPORTED,
17-
KEY_LOG_FILE_SUPPORTED
18+
KEY_LOG_FILE_SUPPORTED,
19+
DESKTOP_SELECT_SAVE_FILE_SUPPORTED
1820
} from '../../services/service-versions';
21+
import { DesktopApi } from '../../services/desktop-api';
1922

2023
import { inputValidation } from '../component-utils';
2124
import {
@@ -88,13 +91,21 @@ const Http2Select = styled(Select)`
8891
padding: 3px;
8992
`;
9093

91-
const TlsKeyLogContainer = styled.div`
94+
const TlsKeyLogInputContainer = styled.div`
9295
margin: 10px 0;
9396
display: flex;
9497
flex-direction: column;
9598
position: relative;
9699
`;
97100

101+
const TlsKeyLogButtonsContainer = styled.div`
102+
display: grid;
103+
grid-template-columns: auto min-content min-content;
104+
grid-gap: 10px;
105+
align-items: center;
106+
font-family: ${p => p.theme.monoFontFamily};
107+
`;
108+
98109
const InputClearButton = styled(IconButton)`
99110
position: absolute;
100111
top: 1px;
@@ -198,6 +209,16 @@ export class ProxySettingsCard extends React.Component<
198209
}
199210
}
200211

212+
@action.bound
213+
async setTlsKeyFilePathFromDialog() {
214+
const path = await DesktopApi.selectSaveFilePath!();
215+
if (!path) return; // Dialog cancelled, change nothing
216+
217+
runInAction(() => {
218+
this.props.proxyStore!.keyLogFilePath = path;
219+
});
220+
}
221+
201222
@action.bound
202223
clearTlsKeyFilePath() {
203224
this.tlsKeyFileInput = '';
@@ -335,24 +356,47 @@ export class ProxySettingsCard extends React.Component<
335356
}
336357
</SettingsSubheading>
337358

338-
<TlsKeyLogContainer>
339-
<TextInput
340-
placeholder={
341-
navigator.platform.startsWith('Win')
342-
? 'C:\\tls-keys.log'
343-
: '/tmp/tls-keys.log'
344-
}
345-
value={this.tlsKeyFileInput}
346-
onChange={this.setTlsKeyFilePath}
347-
/>
348-
{ !!keyLogFilePath && <>
349-
<InputClearButton
350-
title="Unset TLS key file"
351-
icon={['fas', 'times']}
352-
onClick={this.clearTlsKeyFilePath}
353-
/>
354-
</> }
355-
</TlsKeyLogContainer>
359+
<TlsKeyLogInputContainer>
360+
{ versionSatisfies(desktopVersion.value, DESKTOP_SELECT_SAVE_FILE_SUPPORTED)
361+
? !keyLogFilePath
362+
? <SettingsButton
363+
onClick={this.setTlsKeyFilePathFromDialog}
364+
>
365+
Select where to save the TLS keylog file
366+
</SettingsButton>
367+
: <TlsKeyLogButtonsContainer>
368+
{ keyLogFilePath }
369+
<SettingsButton
370+
onClick={this.setTlsKeyFilePathFromDialog}
371+
>
372+
<Icon icon={['fas', 'folder-open']} />
373+
</SettingsButton>
374+
<SettingsButton
375+
onClick={this.clearTlsKeyFilePath}
376+
>
377+
<Icon icon={['far', 'trash-alt']} />
378+
</SettingsButton>
379+
</TlsKeyLogButtonsContainer>
380+
: <>
381+
<TextInput
382+
placeholder={
383+
navigator.platform.startsWith('Win')
384+
? 'C:\\tls-keys.log'
385+
: '/tmp/tls-keys.log'
386+
}
387+
value={this.tlsKeyFileInput}
388+
onChange={this.setTlsKeyFilePath}
389+
/>
390+
{ !!this.tlsKeyFileInput &&
391+
<InputClearButton
392+
title="Unset TLS key file"
393+
icon={['fas', 'times']}
394+
onClick={this.clearTlsKeyFilePath}
395+
/>
396+
}
397+
</>
398+
}
399+
</TlsKeyLogInputContainer>
356400

357401
<SettingsExplanation>
358402
If set, TLS keys for all client & server traffic will be logged to this file,

src/services/desktop-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface DesktopApi {
4141

4242
selectApplication?: () => Promise<string | undefined>;
4343
selectFilePath?: () => Promise<string | undefined>;
44+
selectSaveFilePath?: () => Promise<string | undefined>;
4445

4546
openContextMenu?: (options: NativeContextMenuDefinition) => Promise<string | undefined>;
4647
restartApp?: () => Promise<void>;

src/services/service-versions.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export function serverSupports(versionRequirement: string | undefined) {
5555

5656
// Notable desktop versions:
5757
export const DESKTOP_HEADER_LIMIT_CONFIGURABLE = "^0.1.20 || ^1.0.0";
58+
export const DESKTOP_SELECT_SAVE_FILE_SUPPORTED = "^1.23.0";
5859

5960
// Notable server versions:
6061
export const PORT_RANGE_SERVER_RANGE = '^0.1.14 || ^1.0.0';

0 commit comments

Comments
 (0)