Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
New electron dialog changes
Browse files Browse the repository at this point in the history
requires brave/muon#385

Auditors: @bridiver, @bbondy, @bsclifton

Test Plan:
Specified in PR
  • Loading branch information
darkdh committed Jan 29, 2018
1 parent 5cb5b4a commit 9d31752
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 38 deletions.
18 changes: 8 additions & 10 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,22 @@ const onBootStateFile = (state) => {

const promptForRecoveryKeyFile = () => {
const defaultRecoveryKeyFilePath = path.join(electron.app.getPath('userData'), '/brave_wallet_recovery.txt')
let files
if (process.env.SPECTRON) {
// skip the dialog for tests
console.log(`for test, trying to recover keys from path: ${defaultRecoveryKeyFilePath}`)
files = [defaultRecoveryKeyFilePath]
return defaultRecoveryKeyFilePath
} else {
const dialog = electron.dialog
files = dialog.showOpenDialog({
properties: ['openFile'],
const BrowserWindow = electron.BrowserWindow
dialog.showDialog(BrowserWindow.getFocusedWindow(), {
type: 'select-open-file',
defaultPath: defaultRecoveryKeyFilePath,
filters: [{
name: 'TXT files',
extensions: ['txt']
}]
extensions: [['txt']],
includeAllFiles: false
}, (files) => {
return (files && files.length ? files[0] : null)
})
}

return (files && files.length ? files[0] : null)
}

const logError = (state, err, caller) => {
Expand Down
12 changes: 5 additions & 7 deletions app/browser/bookmarksExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,12 @@ const showDialog = (state) => {
let personal = []
let other = []

dialog.showSaveDialog(focusedWindow, {
dialog.showDialog(focusedWindow, {
defaultPath: defaultPath,
filters: [{
name: 'HTML',
extensions: ['html']
}]
}, (fileName) => {
if (fileName) {
type: 'select-saveas-file',
extensions: [['html']]
}, (fileNames) => {
if (fileNames && fileNames.length === 1) {
personal = createBookmarkArray(state)
other = createBookmarkArray(state, -1, false)
try {
Expand Down
4 changes: 2 additions & 2 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ const createFileSubmenu = () => {
label: locale.translation('openFile'),
accelerator: 'CmdOrCtrl+O',
click: (item, focusedWindow) => {
dialog.showOpenDialog(focusedWindow, {
properties: ['openFile', 'multiSelections']
dialog.showDialog(focusedWindow, {
type: 'select-open-multi-file'
}, (paths) => {
if (paths) {
paths.forEach((path) => {
Expand Down
10 changes: 5 additions & 5 deletions app/browser/reducers/downloadsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ const downloadsReducer = (state, action) => {
case appConstants.APP_SELECT_DEFAULT_DOWNLOAD_PATH:
const focusedWindow = BrowserWindow.getFocusedWindow()

dialog.showOpenDialog(focusedWindow, {
dialog.showDialog(focusedWindow, {
defaultPath: app.getPath('downloads'),
properties: ['openDirectory', 'createDirectory']
}, (folder) => {
if (Array.isArray(folder) && fs.lstatSync(folder[0]).isDirectory()) {
appActions.changeSetting(settings.DOWNLOAD_DEFAULT_PATH, folder[0])
type: 'select-folder'
}, (paths) => {
if (Array.isArray(paths) && fs.lstatSync(paths[0]).isDirectory()) {
appActions.changeSetting(settings.DOWNLOAD_DEFAULT_PATH, paths[0])
}
})
break
Expand Down
18 changes: 8 additions & 10 deletions app/importer.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,15 @@ exports.importHTML = (selected) => {
isImportingBookmarks = true
const state = appStore.getState()
hasBookmarks = bookmarksState.getBookmarks(state).size > 0 || bookmarkFoldersState.getFolders(state).size > 0
const files = dialog.showOpenDialog({
properties: ['openFile'],
filters: [{
name: 'HTML',
extensions: ['html', 'htm']
}]
dialog.showDialog(BrowserWindow.getFocusedWindow(), {
type: 'select-open-file',
extensions: [['html', 'htm']]
}, (files) => {
if (files && files.length === 1) {
const file = files[0]
importer.importHTML(file)
}
})
if (files && files.length > 0) {
const file = files[0]
importer.importHTML(file)
}
}

importer.on('update-supported-browsers', (e, detail) => {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/app/browser/reducers/downloadsReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('downloadsReducer', function () {
let options

before(function () {
stub = sinon.stub(fakeElectron.dialog, 'showOpenDialog', function (arg1, arg2) {
stub = sinon.stub(fakeElectron.dialog, 'showDialog', function (arg1, arg2) {
options = arg2
})
downloadsReducer({}, {actionType: appConstants.APP_SELECT_DEFAULT_DOWNLOAD_PATH})
Expand All @@ -264,7 +264,7 @@ describe('downloadsReducer', function () {
stub.restore()
})

it('calls dialog.showOpenDialog', function () {
it('calls dialog.showDialog', function () {
assert(stub.calledOnce)
})

Expand All @@ -273,7 +273,7 @@ describe('downloadsReducer', function () {
})

it('passes the correct properties object', function () {
assert.deepEqual(options.properties, ['openDirectory', 'createDirectory'])
assert.deepEqual(options.type, 'select-folder')
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/fakeElectron.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const fakeElectron = {
}
},
dialog: {
showOpenDialog: function () { }
showDialog: function () { }
},
Menu: {
setApplicationMenu: (template) => {},
Expand Down

0 comments on commit 9d31752

Please sign in to comment.