Fix deprecated dialog callback functions

This commit is contained in:
hicom150
2019-11-23 00:03:20 +01:00
parent af8b9cf1f2
commit d738021285
4 changed files with 35 additions and 35 deletions

View File

@@ -61,11 +61,10 @@ function openFiles () {
properties: ['openFile'] properties: ['openFile']
} }
setTitle(opts.title) setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) { const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('onOpen', selectedPaths) windows.main.dispatch('onOpen', selectedPaths)
})
} }
/* /*
@@ -80,12 +79,11 @@ function openTorrentFile () {
properties: ['openFile', 'multiSelections'] properties: ['openFile', 'multiSelections']
} }
setTitle(opts.title) setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) { const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
selectedPaths.forEach(function (selectedPath) { selectedPaths.forEach(function (selectedPath) {
windows.main.dispatch('addTorrent', selectedPath) windows.main.dispatch('addTorrent', selectedPath)
})
}) })
} }
@@ -116,9 +114,8 @@ function resetTitle () {
*/ */
function showOpenSeed (opts) { function showOpenSeed (opts) {
setTitle(opts.title) setTitle(opts.title)
electron.dialog.showOpenDialog(windows.main.win, opts, function (selectedPaths) { const selectedPaths = electron.dialog.showOpenDialogSync(windows.main.win, opts)
resetTitle() resetTitle()
if (!Array.isArray(selectedPaths)) return if (!Array.isArray(selectedPaths)) return
windows.main.dispatch('showCreateTorrent', selectedPaths) windows.main.dispatch('showCreateTorrent', selectedPaths)
})
} }

View File

@@ -36,14 +36,9 @@ class PathSelector extends React.Component {
properties: ['openFile', 'openDirectory'] properties: ['openFile', 'openDirectory']
}, this.props.dialog) }, this.props.dialog)
remote.dialog.showOpenDialog( const filenames = remote.dialog.showOpenDialogSync(remote.getCurrentWindow(), opts)
remote.getCurrentWindow(), if (!Array.isArray(filenames)) return
opts, this.props.onChange && this.props.onChange(filenames[0])
(filenames) => {
if (!Array.isArray(filenames)) return
this.props.onChange && this.props.onChange(filenames[0])
}
)
} }
render () { render () {

View File

@@ -13,14 +13,13 @@ module.exports = class SubtitlesController {
} }
openSubtitles () { openSubtitles () {
remote.dialog.showOpenDialog({ const filenames = remote.dialog.showOpenDialogSync({
title: 'Select a subtitles file.', title: 'Select a subtitles file.',
filters: [{ name: 'Subtitles', extensions: ['vtt', 'srt'] }], filters: [{ name: 'Subtitles', extensions: ['vtt', 'srt'] }],
properties: ['openFile'] properties: ['openFile']
}, (filenames) => {
if (!Array.isArray(filenames)) return
this.addSubtitles(filenames, true)
}) })
if (!Array.isArray(filenames)) return
this.addSubtitles(filenames, true)
} }
selectSubtitle (ix) { selectSubtitle (ix) {

View File

@@ -1,15 +1,24 @@
const electron = require('electron') const electron = require('electron')
const config = require('./config') const config = require('./config')
console.log('Mocking electron.dialog.showOpenDialog...') console.log('Mocking electron.dialog.showOpenDialogSync...')
electron.dialog.showOpenDialog = function (win, opts, cb) { electron.dialog.showOpenDialogSync = showOpenDialogSync
const ret = /select.*torrent file/i.test(opts.title)
console.log('Mocking electron.remote.dialog.showOpenDialogSync...')
electron.remote.dialog.showOpenDialogSync = showOpenDialogSync
function showOpenDialogSync (win, opts) {
return /select.*torrent file/i.test(opts.title)
? config.TORRENT_FILES ? config.TORRENT_FILES
: config.SEED_FILES : config.SEED_FILES
cb(ret)
} }
console.log('Mocking electron.remote.dialog.showSaveDialog...') console.log('Mocking electron.dialog.showSaveDialogSync...')
electron.dialog.showSaveDialog = function (win, opts, cb) { electron.dialog.showSaveDialogSync = showSaveDialogSync
cb(config.SAVED_TORRENT_FILE)
console.log('Mocking electron.remote.dialog.showSaveDialogSync...')
electron.remote.dialog.showSaveDialogSync = showSaveDialogSync
function showSaveDialogSync (win, opts) {
return config.SAVED_TORRENT_FILE
} }