External VLC on Windows
Turns out we can't use vlc --version because it pops up a command prompt :/
This commit is contained in:
@@ -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)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
28
main/vlc.js
28
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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user