From 1c7b3ffd4f7bb9f8e78467cb7579c1b48a59a8fd Mon Sep 17 00:00:00 2001 From: Anthony Tseng Date: Mon, 29 Jan 2018 12:56:22 -0800 Subject: [PATCH] Merge pull request #11906 from brave/file_dialog New electron dialog changes --- .npmrc | 4 ++-- app/browser/api/ledger.js | 18 ++++++++---------- app/browser/bookmarksExporter.js | 12 +++++------- app/browser/menu.js | 4 ++-- app/browser/reducers/downloadsReducer.js | 10 +++++----- app/importer.js | 18 ++++++++---------- .../browser/reducers/downloadsReducerTest.js | 6 +++--- test/unit/lib/fakeElectron.js | 2 +- tools/cibuild.py | 2 +- 9 files changed, 35 insertions(+), 41 deletions(-) diff --git a/.npmrc b/.npmrc index e34a373bb68..dbcc6a429ba 100644 --- a/.npmrc +++ b/.npmrc @@ -1,7 +1,7 @@ runtime = electron target_arch = x64 -brave_electron_version = 4.7.9 +brave_electron_version = 5.0.0 chromedriver_version = 2.33 -target = v4.7.9 +target = v5.0.0 disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/ build_from_source = true diff --git a/app/browser/api/ledger.js b/app/browser/api/ledger.js index 88270b346db..8e73c2d2748 100644 --- a/app/browser/api/ledger.js +++ b/app/browser/api/ledger.js @@ -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) => { diff --git a/app/browser/bookmarksExporter.js b/app/browser/bookmarksExporter.js index 9fa11318e95..7665de9a1a1 100644 --- a/app/browser/bookmarksExporter.js +++ b/app/browser/bookmarksExporter.js @@ -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 { diff --git a/app/browser/menu.js b/app/browser/menu.js index 2590beae37b..5aa2a8fd510 100644 --- a/app/browser/menu.js +++ b/app/browser/menu.js @@ -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) => { diff --git a/app/browser/reducers/downloadsReducer.js b/app/browser/reducers/downloadsReducer.js index 5a2c01230bc..174308c28f9 100644 --- a/app/browser/reducers/downloadsReducer.js +++ b/app/browser/reducers/downloadsReducer.js @@ -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 diff --git a/app/importer.js b/app/importer.js index 34219fd875c..1e2d898ecf4 100644 --- a/app/importer.js +++ b/app/importer.js @@ -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) => { diff --git a/test/unit/app/browser/reducers/downloadsReducerTest.js b/test/unit/app/browser/reducers/downloadsReducerTest.js index 0cec81c6e86..c265831adc7 100644 --- a/test/unit/app/browser/reducers/downloadsReducerTest.js +++ b/test/unit/app/browser/reducers/downloadsReducerTest.js @@ -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}) @@ -264,7 +264,7 @@ describe('downloadsReducer', function () { stub.restore() }) - it('calls dialog.showOpenDialog', function () { + it('calls dialog.showDialog', function () { assert(stub.calledOnce) }) @@ -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') }) }) }) diff --git a/test/unit/lib/fakeElectron.js b/test/unit/lib/fakeElectron.js index 07abf352bfb..3df44b59f49 100644 --- a/test/unit/lib/fakeElectron.js +++ b/test/unit/lib/fakeElectron.js @@ -53,7 +53,7 @@ const fakeElectron = { } }, dialog: { - showOpenDialog: function () { } + showDialog: function () { } }, Menu: { setApplicationMenu: (template) => {}, diff --git a/tools/cibuild.py b/tools/cibuild.py index 6ac8d6ac8e1..b66ed57d40c 100755 --- a/tools/cibuild.py +++ b/tools/cibuild.py @@ -4,7 +4,7 @@ import subprocess import sys import os.path -MUON_VERSION = '4.7.9' +MUON_VERSION = '5.0.0' CHROMEDRIVER_VERSION = '2.33' SOURCE_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) TARGET_ARCH= os.environ['TARGET_ARCH'] if os.environ.has_key('TARGET_ARCH') else 'x64'