From 1e487a3c2a3acdd89a6180fe3874b1190681248a Mon Sep 17 00:00:00 2001 From: DC Date: Wed, 4 May 2016 01:48:39 -0700 Subject: [PATCH] Use vlc-command --- main/vlc.js | 61 +++++++++------------------------------------------- package.json | 1 + 2 files changed, 11 insertions(+), 51 deletions(-) diff --git a/main/vlc.js b/main/vlc.js index 125e0b03..63e9acc5 100644 --- a/main/vlc.js +++ b/main/vlc.js @@ -4,14 +4,13 @@ module.exports = { } var cp = require('child_process') -var fs = require('fs') -var path = require('path') +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, stderr) { + exec(['--version'], function (e, stdout) { var version if (e) { version = null @@ -24,59 +23,19 @@ function getInstalledVersion (cb) { }) } -// TODO: make this its own module, to avoid duplicating code with webtorrent-cli -// Finds if VLC is installed on Mac, Windows, or Linux and runs it function exec (args, cb) { - execOrSpawn(args, true, 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. // Uses child_process.spawn() to return a ChildProcess object // Calls back with (err, childProcess) function spawn (args, cb) { - execOrSpawn(args, false, cb) -} - -function execOrSpawn (args, isExec, cb) { - if (process.platform === 'win32') { - var Registry = require('winreg') - - var key - if (process.arch === 'x64') { - key = new Registry({ - hive: Registry.HKLM, - key: '\\Software\\Wow6432Node\\VideoLAN\\VLC' - }) - } else { - key = new Registry({ - hive: Registry.HKLM, - key: '\\Software\\VideoLAN\\VLC' - }) - } - - key.get('InstallDir', function (err, item) { - if (err) return cb(err) - var vlcPath = item.value + path.sep + 'vlc' - if (isExec) cp.execFile(vlcPath, args, cb) - else cb(null, cp.spawn(vlcPath, args)) - }) - } else { - var macRoot = '/Applications/VLC.app/Contents/MacOS/VLC' - var macHome = (process.env.HOME || '') + root - var locations = [macRoot, macHome, '/usr/bin/vlc'] - var found = false - var failed = 0 - locations.forEach(function (loc) { - fs.stat(loc, function (err) { - if (err) { - if (++failed === locations.length) cb(new Error('Can\'t find VLC')) - return - } - if (found) return - found = true - if (isExec) cp.execFile(loc, args, cb) - else cb(null, cp.spawn(loc, args)) - }) - }) - } + vlcCommand(function (err, vlcPath) { + if (err) return cb(err) + cb(null, cp.spawn(vlcPath, args)) + }) } diff --git a/package.json b/package.json index 8b9c1ec6..c3c0568b 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "simple-get": "^2.0.0", "srt-to-vtt": "^1.1.1", "virtual-dom": "^2.1.1", + "vlc-command": "^1.0.1", "webtorrent": "0.x", "winreg": "^1.2.0" },