From b728e2bed084f42ff2b58642afc5e1664e3e1ce8 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 3 Feb 2017 11:37:18 +0100 Subject: [PATCH] Added default download path Resolves #2110 Auditors: @bradleyrichter @bsclifton Test Plan: - go to preferences, general tab - define your default download path - toggle show dialog - based on your settings, download dialog should be opened or not - if you set don't show dialog, filse should be downloaded to your default set path --- app/browser/reducers/downloadsReducer.js | 19 +++++++++++++++++-- .../locales/en-US/preferences.properties | 2 ++ app/filtering.js | 4 ++-- js/about/aboutActions.js | 9 +++++++++ js/about/preferences.js | 15 +++++++++++++++ js/constants/appConfig.js | 2 ++ js/constants/appConstants.js | 1 + js/constants/settings.js | 2 ++ 8 files changed, 50 insertions(+), 4 deletions(-) diff --git a/app/browser/reducers/downloadsReducer.js b/app/browser/reducers/downloadsReducer.js index 02547ab1200..5f4d16da032 100644 --- a/app/browser/reducers/downloadsReducer.js +++ b/app/browser/reducers/downloadsReducer.js @@ -6,17 +6,20 @@ const appConstants = require('../../../js/constants/appConstants') const downloadStates = require('../../../js/constants/downloadStates') -const {clipboard, BrowserWindow, shell} = require('electron') +const settings = require('../../../js/constants/settings') +const {clipboard, BrowserWindow, shell, dialog, app} = require('electron') const fs = require('fs') const path = require('path') const {cancelDownload, pauseDownload, resumeDownload} = require('../electronDownloadItem') const {CANCEL, PAUSE, RESUME} = require('../../common/constants/electronDownloadItemActions') +const appActions = require('../../../js/actions/appActions') const downloadsReducer = (state, action) => { const download = action.downloadId ? state.getIn(['downloads', action.downloadId]) : undefined if (!download && ![appConstants.APP_MERGE_DOWNLOAD_DETAIL, - appConstants.APP_CLEAR_COMPLETED_DOWNLOADS].includes(action.actionType)) { + appConstants.APP_CLEAR_COMPLETED_DOWNLOADS, + appConstants.APP_DOWNLOAD_DEFAULT_PATH].includes(action.actionType)) { return state } switch (action.actionType) { @@ -89,6 +92,18 @@ const downloadsReducer = (state, action) => { state = state.set('downloads', downloads) } break + case appConstants.APP_DOWNLOAD_DEFAULT_PATH: + const focusedWindow = BrowserWindow.getFocusedWindow() + + dialog.showOpenDialog(focusedWindow, { + defaultPath: app.getPath('downloads'), + properties: ['openDirectory'] + }, (folder) => { + if (Array.isArray(folder) && fs.lstatSync(folder[0]).isDirectory()) { + appActions.changeSetting(settings.DOWNLOAD_DEFAULT_PATH, folder[0]) + } + }) + break } return state } diff --git a/app/extensions/brave/locales/en-US/preferences.properties b/app/extensions/brave/locales/en-US/preferences.properties index 0ce1af0a59b..f1cba2a2344 100644 --- a/app/extensions/brave/locales/en-US/preferences.properties +++ b/app/extensions/brave/locales/en-US/preferences.properties @@ -142,6 +142,8 @@ newTabDefaultSearchEngine=Default search engine newTabEmpty=Blank page myHomepage=My home page is multipleHomePages.title=Multiple home pages +downloadDefaultPath=Save my downloads here: +downloadAlwaysAsk=Always ask me where to save files aboutBlank=about:blank default=Default searchEngine=Search Engine diff --git a/app/filtering.js b/app/filtering.js index 4a29c01253f..61734b32579 100644 --- a/app/filtering.js +++ b/app/filtering.js @@ -498,8 +498,8 @@ function registerForDownloadListener (session) { itemFilename = item.getFilename() } - const defaultPath = path.join(getSetting(settings.DEFAULT_DOWNLOAD_SAVE_PATH) || app.getPath('downloads'), itemFilename) - const savePath = (process.env.SPECTRON ? defaultPath : dialog.showSaveDialog(win, { defaultPath })) + const defaultPath = path.join(getSetting(settings.DOWNLOAD_DEFAULT_PATH) || getSetting(settings.DEFAULT_DOWNLOAD_SAVE_PATH) || app.getPath('downloads'), itemFilename) + const savePath = ((process.env.SPECTRON || !getSetting(settings.DOWNLOAD_ALWAYS_ASK)) ? defaultPath : dialog.showSaveDialog(win, { defaultPath })) // User cancelled out of save dialog prompt if (!savePath) { diff --git a/js/about/aboutActions.js b/js/about/aboutActions.js index 00a9fab1751..c16dd5724c9 100644 --- a/js/about/aboutActions.js +++ b/js/about/aboutActions.js @@ -384,6 +384,15 @@ const aboutActions = { url: url, savePath: savePath }) + }, + + /** + * Open dialog for default download path setting + */ + defaultDownloadPath: function () { + aboutActions.dispatchAction({ + actionType: appConstants.APP_DOWNLOAD_DEFAULT_PATH + }) } } module.exports = aboutActions diff --git a/js/about/preferences.js b/js/about/preferences.js index 098082b1288..9c08750bf49 100644 --- a/js/about/preferences.js +++ b/js/about/preferences.js @@ -560,6 +560,10 @@ class GeneralTab extends ImmutableComponent { return keyArray.every((key) => getSetting(key, this.props.settings) === true) } + openDownloadDialog () { + aboutActions.defaultDownloadPath() + } + render () { var languageOptions = this.props.languageCodes.map(function (lc) { return ( @@ -625,6 +629,17 @@ class GeneralTab extends ImmutableComponent { isDarwin ? null : } + + + + diff --git a/js/constants/appConfig.js b/js/constants/appConfig.js index 122bd9e1837..c067f75590b 100644 --- a/js/constants/appConfig.js +++ b/js/constants/appConfig.js @@ -113,6 +113,8 @@ module.exports = { 'general.useragent.value': null, // Set at runtime 'general.autohide-menu': true, 'general.check-default-on-startup': true, + 'general.download-default-path': '', + 'general.download-always-ask': true, 'search.default-search-engine': 'Google', 'search.offer-search-suggestions': false, // false by default for privacy reasons 'tabs.switch-to-new-tabs': false, diff --git a/js/constants/appConstants.js b/js/constants/appConstants.js index 61fd876eb20..89ef5518706 100644 --- a/js/constants/appConstants.js +++ b/js/constants/appConstants.js @@ -78,6 +78,7 @@ const appConstants = { APP_DOWNLOAD_DELETED: _, APP_DOWNLOAD_CLEARED: _, APP_DOWNLOAD_REDOWNLOADED: _, + APP_DOWNLOAD_DEFAULT_PATH: _, APP_ALLOW_FLASH_ONCE: _, APP_ALLOW_FLASH_ALWAYS: _, APP_FLASH_PERMISSION_REQUESTED: _, diff --git a/js/constants/settings.js b/js/constants/settings.js index 5d0c1e7f72d..6fb4f43c3c6 100644 --- a/js/constants/settings.js +++ b/js/constants/settings.js @@ -16,6 +16,8 @@ const settings = { LANGUAGE: 'general.language', CHECK_DEFAULT_ON_STARTUP: 'general.check-default-on-startup', IS_DEFAULT_BROWSER: 'general.is-default-browser', + DOWNLOAD_DEFAULT_PATH: 'general.download-default-path', + DOWNLOAD_ALWAYS_ASK: 'general.download-always-ask', // Search tab DEFAULT_SEARCH_ENGINE: 'search.default-search-engine', OFFER_SEARCH_SUGGESTIONS: 'search.offer-search-suggestions',