use default path in windows when choosing a file (#7625)

* use default path in windows when choosing a file

* fix, changed var to let
This commit is contained in:
Byron Eric Perez 2022-06-28 16:49:41 -03:00 committed by GitHub
parent 8c10617259
commit c7ab47f54d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 2 deletions

View file

@ -47,7 +47,24 @@ class FileSelector extends React.PureComponent<Props> {
};
handleDirectoryInputSelection = () => {
remote.dialog.showOpenDialog({ properties: ['openDirectory'] }).then((result) => {
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;
}
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<Props> {
autoFocus={autoFocus}
button="primary"
disabled={disabled}
onClick={type === 'openDirectory' ? this.handleDirectoryInputSelection : this.fileInputButton}
onClick={
type === 'openDirectory' || type === 'openFile'
? this.handleDirectoryInputSelection
: this.fileInputButton
}
label={__('Browse')}
/>
}

View file

@ -325,6 +325,7 @@ function PublishFile(props: Props) {
{showFileUpload && (
<>
<FileSelector
type="openFile"
label={__('File')}
disabled={disabled}
currentPath={currentFile}