use default path in windows when choosing a file #7625
2 changed files with 24 additions and 2 deletions
|
@ -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')}
|
||||
/>
|
||||
}
|
||||
|
|
|
@ -325,6 +325,7 @@ function PublishFile(props: Props) {
|
|||
{showFileUpload && (
|
||||
<>
|
||||
<FileSelector
|
||||
type="openFile"
|
||||
label={__('File')}
|
||||
disabled={disabled}
|
||||
currentPath={currentFile}
|
||||
|
|
Loading…
Reference in a new issue
nice,
tested in console in linux
x = require('@electron/remote')
x.dialog.showOpenDialog({properties: ['openFile'], defaultPath: undefined})
And it worked fine.