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 Nov 16, 2017
1 parent 2674950 commit 6962120
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 32 deletions.
10 changes: 4 additions & 6 deletions app/browser/api/ledger.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,11 @@ const promptForRecoveryKeyFile = () => {
files = [defaultRecoveryKeyFilePath]
} else {
const dialog = electron.dialog
files = dialog.showOpenDialog({
properties: ['openFile'],
files = dialog.showDialog({
type: 'select-open-file',
defaultPath: defaultRecoveryKeyFilePath,
filters: [{
name: 'TXT files',
extensions: ['txt']
}]
extensions: [['txt']],
includeAllFiles: false
})
}

Expand Down
14 changes: 6 additions & 8 deletions app/browser/bookmarksExporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,15 @@ 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)
fs.writeFileSync(fileName, createBookmarkHTML(personal, other))
fs.writeFileSync(fileNames[0], createBookmarkHTML(personal, other))
}
})
}
Expand Down
5 changes: 3 additions & 2 deletions app/browser/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ const createFileSubmenu = () => {
label: locale.translation('openFile'),
accelerator: 'CmdOrCtrl+O',
click: (item, focusedWindow) => {
dialog.showOpenDialog(focusedWindow, {
properties: ['openFile', 'multiSelections']
dialog.showDialog(focusedWindow, {
title: locale.translation('openFile'),
type: 'select-open-multi-file'
}, (paths) => {
if (paths) {
paths.forEach((path) => {
Expand Down
4 changes: 2 additions & 2 deletions app/browser/reducers/downloadsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ 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']
type: 'select-folder'
}, (folder) => {
if (Array.isArray(folder) && fs.lstatSync(folder[0]).isDirectory()) {
appActions.changeSetting(settings.DOWNLOAD_DEFAULT_PATH, folder[0])
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({
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 @@ -228,7 +228,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 @@ -238,7 +238,7 @@ describe('downloadsReducer', function () {
stub.restore()
})

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

Expand All @@ -247,7 +247,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 @@ -65,7 +65,7 @@ const fakeElectron = {
}
},
dialog: {
showOpenDialog: function () { }
showDialog: function () { }
},
Menu: {
setApplicationMenu: (template) => {},
Expand Down

0 comments on commit 6962120

Please sign in to comment.