[MM-22013] - Allow users to specify default download locations (#1383)
* [MM-22013] - Allow users to specify default download locations * PR comments * Add proper config prop * Update src/browser/components/SettingsPage.jsx Co-authored-by: Guillermo Vayá <guillermo.vaya@mattermost.com> * Remove string ref * Fix styling * Update styling * Disable input * Add variable for windows * Prevent dialog from opening twice Co-authored-by: Nevyana Angelova <nevyangelova@Nevyanas-MBP-2.fritz.box> Co-authored-by: Nevyana Angelova <nevyangelova@Nevyanas-MacBook-Pro-2.local> Co-authored-by: Guillermo Vayá <guillermo.vaya@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
This commit is contained in:
parent
98c7aed105
commit
ad1871ad95
|
@ -44,9 +44,11 @@ export default class SettingsPage extends React.Component {
|
||||||
this.state = this.convertConfigDataToState(config.data);
|
this.state = this.convertConfigDataToState(config.data);
|
||||||
this.setState({
|
this.setState({
|
||||||
maximized: false,
|
maximized: false,
|
||||||
|
userOpenedDownloadGialog: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.trayIconThemeRef = React.createRef();
|
this.trayIconThemeRef = React.createRef();
|
||||||
|
this.downloadLocationRef = React.createRef();
|
||||||
|
|
||||||
this.saveQueue = [];
|
this.saveQueue = [];
|
||||||
}
|
}
|
||||||
|
@ -418,6 +420,29 @@ export default class SettingsPage extends React.Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveDownloadLocation = (location) => {
|
||||||
|
this.setState({
|
||||||
|
downloadLocation: location,
|
||||||
|
});
|
||||||
|
setImmediate(this.saveSetting, CONFIG_TYPE_APP_OPTIONS, {key: 'downloadLocation', data: location});
|
||||||
|
}
|
||||||
|
|
||||||
|
handleChangeDownloadLocation = (e) => {
|
||||||
|
this.saveDownloadLocation(e.target.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
selectDownloadLocation = () => {
|
||||||
|
if (!this.state.userOpenedDownloadGialog) {
|
||||||
|
const message = 'Specify the folder where files will download';
|
||||||
|
remote.dialog.showOpenDialog({defaultPath: `/Users/${process.env.USER || process.env.USERNAME}/Downloads`,
|
||||||
|
message,
|
||||||
|
properties:
|
||||||
|
['openDirectory', 'createDirectory', 'dontAddToRecent', 'promptToCreate']}).then((result) => this.saveDownloadLocation(result.filePaths[0]));
|
||||||
|
this.setState({userOpenedDownloadGialog: true});
|
||||||
|
}
|
||||||
|
this.setState({userOpenedDownloadGialog: false});
|
||||||
|
}
|
||||||
|
|
||||||
updateTeam = (index, newData) => {
|
updateTeam = (index, newData) => {
|
||||||
const teams = this.state.localTeams;
|
const teams = this.state.localTeams;
|
||||||
teams[index] = newData;
|
teams[index] = newData;
|
||||||
|
@ -620,6 +645,25 @@ export default class SettingsPage extends React.Component {
|
||||||
footer: {
|
footer: {
|
||||||
padding: '0.4em 0',
|
padding: '0.4em 0',
|
||||||
},
|
},
|
||||||
|
|
||||||
|
downloadLocationInput: {
|
||||||
|
marginRight: '3px',
|
||||||
|
marginTop: '8px',
|
||||||
|
width: '320px',
|
||||||
|
height: '34px',
|
||||||
|
padding: '0 12px',
|
||||||
|
borderRadius: '4px',
|
||||||
|
border: '1px solid #ccc',
|
||||||
|
fontWeight: '500',
|
||||||
|
},
|
||||||
|
|
||||||
|
downloadLocationButton: {
|
||||||
|
marginBottom: '4px',
|
||||||
|
},
|
||||||
|
|
||||||
|
container: {
|
||||||
|
paddingBottom: '40px',
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const teamsRow = (
|
const teamsRow = (
|
||||||
|
@ -877,6 +921,32 @@ export default class SettingsPage extends React.Component {
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
options.push(
|
||||||
|
<div style={settingsPage.container}>
|
||||||
|
<hr/>
|
||||||
|
<div>{'Download Location'}</div>
|
||||||
|
<input
|
||||||
|
disabled={true}
|
||||||
|
style={settingsPage.downloadLocationInput}
|
||||||
|
key='inputDownloadLocation'
|
||||||
|
id='inputDownloadLocation'
|
||||||
|
ref={this.downloadLocationRef}
|
||||||
|
onChange={this.handleChangeDownloadLocation}
|
||||||
|
value={this.state.downloadLocation}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
style={settingsPage.downloadLocationButton}
|
||||||
|
id='saveDownloadLocation'
|
||||||
|
onClick={this.selectDownloadLocation}
|
||||||
|
>
|
||||||
|
<span>{'Change'}</span>
|
||||||
|
</Button>
|
||||||
|
<HelpBlock>
|
||||||
|
{'Specify the folder where files will download.'}
|
||||||
|
</HelpBlock>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
|
||||||
const optionsRow = (options.length > 0) ? (
|
const optionsRow = (options.length > 0) ? (
|
||||||
<Row>
|
<Row>
|
||||||
<Col md={12}>
|
<Col md={12}>
|
||||||
|
|
|
@ -23,6 +23,7 @@ const defaultPreferences = {
|
||||||
autostart: true,
|
autostart: true,
|
||||||
spellCheckerLocale: 'en-US',
|
spellCheckerLocale: 'en-US',
|
||||||
darkMode: false,
|
darkMode: false,
|
||||||
|
downloadLocation: `/Users/${process.env.USER || process.env.USERNAME}/Downloads`
|
||||||
};
|
};
|
||||||
|
|
||||||
export default defaultPreferences;
|
export default defaultPreferences;
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||||
// See LICENSE.txt for license information.
|
// See LICENSE.txt for license information.
|
||||||
|
|
||||||
import os from 'os';
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
|
@ -783,7 +782,7 @@ function initializeAfterAppReady() {
|
||||||
});
|
});
|
||||||
item.setSaveDialogOptions({
|
item.setSaveDialogOptions({
|
||||||
title: filename,
|
title: filename,
|
||||||
defaultPath: os.homedir() + '/Downloads/' + filename,
|
defaultPath: path.resolve(config.combinedData.downloadLocation, filename),
|
||||||
filters,
|
filters,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -80,6 +80,7 @@ const configDataSchemaV2 = Joi.object({
|
||||||
autostart: Joi.boolean().default(true),
|
autostart: Joi.boolean().default(true),
|
||||||
spellCheckerLocale: Joi.string().regex(/^[a-z]{2}-[A-Z]{2}$/).default('en-US'),
|
spellCheckerLocale: Joi.string().regex(/^[a-z]{2}-[A-Z]{2}$/).default('en-US'),
|
||||||
darkMode: Joi.boolean().default(false),
|
darkMode: Joi.boolean().default(false),
|
||||||
|
downloadLocation: Joi.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// eg. data['community.mattermost.com'] = { data: 'certificate data', issuerName: 'COMODO RSA Domain Validation Secure Server CA'};
|
// eg. data['community.mattermost.com'] = { data: 'certificate data', issuerName: 'COMODO RSA Domain Validation Secure Server CA'};
|
||||||
|
|
Loading…
Reference in a new issue