From ad1871ad9579f8e1ee70748dbcab2e393f5c6d33 Mon Sep 17 00:00:00 2001 From: Nev Angelova Date: Tue, 3 Nov 2020 11:25:48 +0000 Subject: [PATCH] [MM-22013] - Allow users to specify default download locations (#1383) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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Ć” * Remove string ref * Fix styling * Update styling * Disable input * Add variable for windows * Prevent dialog from opening twice Co-authored-by: Nevyana Angelova Co-authored-by: Nevyana Angelova Co-authored-by: Guillermo VayĆ” Co-authored-by: Mattermod --- src/browser/components/SettingsPage.jsx | 70 +++++++++++++++++++++++++ src/common/config/defaultPreferences.js | 1 + src/main.js | 3 +- src/main/Validator.js | 1 + 4 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/browser/components/SettingsPage.jsx b/src/browser/components/SettingsPage.jsx index d830f631..668caa56 100644 --- a/src/browser/components/SettingsPage.jsx +++ b/src/browser/components/SettingsPage.jsx @@ -44,9 +44,11 @@ export default class SettingsPage extends React.Component { this.state = this.convertConfigDataToState(config.data); this.setState({ maximized: false, + userOpenedDownloadGialog: false, }); this.trayIconThemeRef = React.createRef(); + this.downloadLocationRef = React.createRef(); 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) => { const teams = this.state.localTeams; teams[index] = newData; @@ -620,6 +645,25 @@ export default class SettingsPage extends React.Component { footer: { 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 = ( @@ -877,6 +921,32 @@ export default class SettingsPage extends React.Component { ); + options.push( +
+
+
{'Download Location'}
+ + + + {'Specify the folder where files will download.'} + +
+ ); + const optionsRow = (options.length > 0) ? ( diff --git a/src/common/config/defaultPreferences.js b/src/common/config/defaultPreferences.js index d8de17e4..d7b5cff5 100644 --- a/src/common/config/defaultPreferences.js +++ b/src/common/config/defaultPreferences.js @@ -23,6 +23,7 @@ const defaultPreferences = { autostart: true, spellCheckerLocale: 'en-US', darkMode: false, + downloadLocation: `/Users/${process.env.USER || process.env.USERNAME}/Downloads` }; export default defaultPreferences; diff --git a/src/main.js b/src/main.js index b4f1b6e7..27092b63 100644 --- a/src/main.js +++ b/src/main.js @@ -2,7 +2,6 @@ // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import os from 'os'; import path from 'path'; import fs from 'fs'; @@ -783,7 +782,7 @@ function initializeAfterAppReady() { }); item.setSaveDialogOptions({ title: filename, - defaultPath: os.homedir() + '/Downloads/' + filename, + defaultPath: path.resolve(config.combinedData.downloadLocation, filename), filters, }); diff --git a/src/main/Validator.js b/src/main/Validator.js index 81d17118..c17e88f0 100644 --- a/src/main/Validator.js +++ b/src/main/Validator.js @@ -80,6 +80,7 @@ const configDataSchemaV2 = Joi.object({ autostart: Joi.boolean().default(true), spellCheckerLocale: Joi.string().regex(/^[a-z]{2}-[A-Z]{2}$/).default('en-US'), darkMode: Joi.boolean().default(false), + downloadLocation: Joi.string(), }); // eg. data['community.mattermost.com'] = { data: 'certificate data', issuerName: 'COMODO RSA Domain Validation Secure Server CA'};