From bfe3238281547d76a5d61dd5412dcbe03535536c Mon Sep 17 00:00:00 2001 From: ByronEricPerez Date: Fri, 24 Jun 2022 16:26:24 -0300 Subject: [PATCH 1/2] use default path in windows when choosing a file --- ui/component/common/file-selector.jsx | 25 +++++++++++++++++++++++-- ui/component/publishFile/view.jsx | 1 + 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ui/component/common/file-selector.jsx b/ui/component/common/file-selector.jsx index fda7b11d7..272c9f5e5 100644 --- a/ui/component/common/file-selector.jsx +++ b/ui/component/common/file-selector.jsx @@ -47,7 +47,24 @@ class FileSelector extends React.PureComponent { }; handleDirectoryInputSelection = () => { - remote.dialog.showOpenDialog({ properties: ['openDirectory'] }).then((result) => { + var defaultPath; + var properties; + var isWin = process.platform === 'win32'; + var type = this.props.type; + + if (isWin === true) { + defaultPath = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; + } + + if (type === 'openFile') { + properties = ['openFile']; + } + + if (type === 'openDirectory') { + properties = ['openDirectory']; + } + + remote.dialog.showOpenDialog({ properties, defaultPath }).then((result) => { const path = result && result.filePaths[0]; if (path) { // $FlowFixMe @@ -82,7 +99,11 @@ class FileSelector extends React.PureComponent { autoFocus={autoFocus} button="primary" disabled={disabled} - onClick={type === 'openDirectory' ? this.handleDirectoryInputSelection : this.fileInputButton} + onClick={ + type === 'openDirectory' || type === 'openFile' + ? this.handleDirectoryInputSelection + : this.fileInputButton + } label={__('Browse')} /> } diff --git a/ui/component/publishFile/view.jsx b/ui/component/publishFile/view.jsx index cc57aca89..b53b7720c 100644 --- a/ui/component/publishFile/view.jsx +++ b/ui/component/publishFile/view.jsx @@ -325,6 +325,7 @@ function PublishFile(props: Props) { {showFileUpload && ( <> Date: Tue, 28 Jun 2022 09:04:11 -0300 Subject: [PATCH 2/2] fix, changed var to let --- ui/component/common/file-selector.jsx | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ui/component/common/file-selector.jsx b/ui/component/common/file-selector.jsx index 272c9f5e5..bd1729d31 100644 --- a/ui/component/common/file-selector.jsx +++ b/ui/component/common/file-selector.jsx @@ -47,10 +47,10 @@ class FileSelector extends React.PureComponent { }; handleDirectoryInputSelection = () => { - var defaultPath; - var properties; - var isWin = process.platform === 'win32'; - var type = this.props.type; + let defaultPath; + let properties; + let isWin = process.platform === 'win32'; + let type = this.props.type; if (isWin === true) { defaultPath = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE; -- 2.45.2