Skip to content

Commit

Permalink
Added default download path
Browse files Browse the repository at this point in the history
Resolves brave#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
  • Loading branch information
NejcZdovc committed Feb 12, 2017
1 parent b9e4ed0 commit b728e2b
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 4 deletions.
19 changes: 17 additions & 2 deletions app/browser/reducers/downloadsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions app/extensions/brave/locales/en-US/preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions js/about/aboutActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -625,6 +629,17 @@ class GeneralTab extends ImmutableComponent {
isDarwin ? null : <SettingCheckbox dataL10nId='autoHideMenuBar' prefKey={settings.AUTO_HIDE_MENU} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
}
<SettingCheckbox dataL10nId='disableTitleMode' prefKey={settings.DISABLE_TITLE_MODE} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting} />
<SettingItem dataL10nId='downloadDefaultPath'>
<SettingTextbox
spellCheck='false'
readOnly='true'
data-l10n-id='downloadDefaultPathInput'
value={getSetting(settings.DOWNLOAD_DEFAULT_PATH, this.props.settings)}
onClick={this.openDownloadDialog} />
</SettingItem>
<SettingCheckbox dataL10nId='downloadAlwaysAsk' prefKey={settings.DOWNLOAD_ALWAYS_ASK}
settings={this.props.settings}
onChangeSetting={this.props.onChangeSetting} />
<SettingItem dataL10nId='bookmarkToolbarSettings'>
<SettingDropdown id='bookmarksBarSelect' value={getSetting(settings.BOOKMARKS_TOOLBAR_MODE, this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.BOOKMARKS_TOOLBAR_MODE)}>
Expand Down
2 changes: 2 additions & 0 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions js/constants/appConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: _,
Expand Down
2 changes: 2 additions & 0 deletions js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit b728e2b

Please sign in to comment.