Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ dist

config/*
cache/*
package-lock.json
55 changes: 35 additions & 20 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,64 @@
*/
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',
};

// 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
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)
});
}