11import * as _ from 'lodash' ;
22import * as React from 'react' ;
3- import { observable , action , computed } from 'mobx' ;
3+ import { observable , action , computed , runInAction } from 'mobx' ;
44import { observer , inject } from "mobx-react" ;
55
66import { styled } from '../../styles' ;
@@ -11,11 +11,14 @@ import { isValidPortConfiguration, ProxyStore } from '../../model/proxy-store';
1111import { isValidHostname } from '../../model/network' ;
1212import {
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
2023import { inputValidation } from '../component-utils' ;
2124import {
@@ -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+
98109const 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 ,
0 commit comments