diff --git a/.gitignore b/.gitignore index b033379..4b20572 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,4 @@ dist config/* cache/* +package-lock.json \ No newline at end of file diff --git a/src/app.js b/src/app.js index ff6717f..cecacb6 100755 --- a/src/app.js +++ b/src/app.js @@ -4,15 +4,18 @@ */ const { spawn } = require('child_process'); const fs = require('fs'); +const os = require('os') const config = require('./helpers/configLoader.js').getOrInit('config.js'); const log = require('./helpers/lager.js'); require('./rpc/client.js'); -const platformDefaults= { +const platformDefaults = { win32: 'C:/Program Files/VideoLAN/VLC/vlc.exe', // Alternative path to Windows VLC executable winalt: 'C:/Program Files (x86)/VideoLAN/VLC/vlc.exe', linux: '/usr/bin/vlc', + // Alternative path if you were using flatpak instead of apt/dnf/pacman/etc... + flatpak: '/var/lib/flatpak/app/org.videolan.VLC/x86_64/stable/active/export/bin/org.videolan.VLC', unix: '/usr/bin/vlc', // Mac OS darwin: '/Applications/VLC.app/Contents/MacOS/VLC', @@ -20,9 +23,9 @@ const platformDefaults= { // Generates a random password function randomPass() { - return Math.random() - .toString(36) - .slice(-8); + return Math.random() + .toString(36) + .slice(-8); } // Use a random password if none is supplied @@ -30,23 +33,35 @@ if (config.vlc.password === "") config.vlc.password = randomPass(); log('Started, config', config); if (!(config.rpc.detached || process.argv.includes('detached'))) { - if(process.platform === "win32"){ - if(!fs.existsSync(platformDefaults.win32)){ + if (process.platform === "win32") { + if (!fs.existsSync(platformDefaults.win32)) { // Use alternative Windows path - platformDefaults.win32=platformDefaults.winalt; + platformDefaults.win32 = platformDefaults.winalt; } } - const command = config.vlcPath || platformDefaults[process.platform] || 'vlc'; - const child = spawn(command, ['--extraintf', 'http', '--http-host', config.vlc.address, '--http-password', config.vlc.password, '--http-port', config.vlc.port]); - child.on('exit', () => { - console.log("VLC closed; Exiting."); - process.exit(0); - }); - child.on('error', () => { - console.log("------------------------------------"); - console.log("ERROR: A problem occurred while launching VLC. Most likely, you installed VLC to a weird spot and will need to set the vlcPath value in config/config.js to the path to your vlc executable (eg. vlcPath: \"C:/Program Files/videolan/vlc/vlc.exe\")"); - console.log("------------------------------------"); - console.log("Waiting 20 seconds before exiting to give you time to read the error message :)"); - setTimeout(process.exit, 20000, 1) - }); + if (process.platform === "linux") { + if (fs.existsSync(platformDefaults.flatpak)) { + // If linux path doesn't exist (which is likely if you don't use apt/dnf/pacman). + platformDefaults.linux = platformDefaults.flatpak; + } else { + const flatpakUserPath = `${os.homedir()}/.local/share/flatpak/app/org.videolan.VLC/x86_64/stable/active/export/bin/org.videolan.VLC`; + if (fs.existsSync(flatpakUserPath)) { + platformDefaults.linux = flatpakUserPath; + } + } + } + + const command = config.vlcPath || platformDefaults[process.platform] || 'vlc'; + const child = spawn(command, ['--extraintf', 'http', '--http-host', config.vlc.address, '--http-password', config.vlc.password, '--http-port', config.vlc.port]); + child.on('exit', () => { + console.log("VLC closed; Exiting."); + process.exit(0); + }); + child.on('error', () => { + console.log("------------------------------------"); + console.log("ERROR: A problem occurred while launching VLC. Most likely, you installed VLC to a weird spot and will need to set the vlcPath value in config/config.js to the path to your vlc executable (eg. vlcPath: \"C:/Program Files/videolan/vlc/vlc.exe\")"); + console.log("------------------------------------"); + console.log("Waiting 20 seconds before exiting to give you time to read the error message :)"); + setTimeout(process.exit, 20000, 1) + }); }