diff --git a/main/ipc.js b/main/ipc.js index 4bb55627..d494c620 100644 --- a/main/ipc.js +++ b/main/ipc.js @@ -92,9 +92,9 @@ function init () { windows.focusWindow(windows[windowName]) }) - ipcMain.on('vlcVersion', function (e) { - vlc.getInstalledVersion(function (version) { - windows.main.send('vlcVersion', version) + ipcMain.on('checkForVLC', function (e) { + vlc.checkForVLC(function (isInstalled) { + windows.main.send('checkForVLC', isInstalled) }) }) diff --git a/main/vlc.js b/main/vlc.js index 63e9acc5..b619a047 100644 --- a/main/vlc.js +++ b/main/vlc.js @@ -1,33 +1,15 @@ module.exports = { - getInstalledVersion, + checkForVLC, spawn } var cp = require('child_process') var vlcCommand = require('vlc-command') -// Runs vlc --version. Calls back with the currently installed version of VLC -// or null if VLC is not installed. (Or 'unknown' if VLC runs and produces bad -// output, but that should never happen.) -function getInstalledVersion (cb) { - exec(['--version'], function (e, stdout) { - var version - if (e) { - version = null - } else { - // Prints several lines, starting with eg: VLC media player 2.7.0 - if (!stdout.startsWith('VLC media player')) version = 'unknown' - else version = stdout.split(' ')[3] - } - cb(version) - }) -} - -function exec (args, cb) { - vlcCommand(function (err, vlcPath) { - if (err) return cb(err) - cp.execFile(vlcPath, args, cb) - }) +// Finds if VLC is installed on Mac, Windows, or Linux. +// Calls back with true or false: whether VLC was detected +function checkForVLC (cb) { + vlcCommand((err) => cb(!err)) } // Finds if VLC is installed on Mac, Windows, or Linux. diff --git a/renderer/index.js b/renderer/index.js index 9fc22451..8319766a 100644 --- a/renderer/index.js +++ b/renderer/index.js @@ -306,13 +306,12 @@ function dispatch (action, ...args) { if (action === 'mediaError') { if (state.location.current().url === 'player') { state.playing.location = 'error' - ipcRenderer.send('vlcVersion') - ipcRenderer.once('vlcVersion', function (e, version) { - console.log('vlcVersion', version) + ipcRenderer.send('checkForVLC') + ipcRenderer.once('checkForVLC', function (e, isInstalled) { state.modal = { id: 'unsupported-media-modal', error: args[0], - vlcInstalled: !!version + vlcInstalled: isInstalled } }) }