midi: detect missing binary (eg when deleted by antivirus) and print a message

This commit is contained in:
bordun 2021-06-12 14:26:09 +02:00
parent c5c3c992f2
commit ee675a7dbd
3 changed files with 26 additions and 3 deletions

View file

@ -18,11 +18,19 @@ var midiBinaries = {
win32: 'osc-midi-windows.exe'
}
var expectMidiBinaries = false,
expectMidiBinariesError = false;
try {
expectMidiBinaries = eval('require("./osc-midi.json")');
} catch(e) {}
var pythonPathOverride
if (process.arch === 'x64' && midiBinaries[process.platform]) {
var p = path.resolve(__dirname, midiBinaries[process.platform])
if (fs.existsSync(p)) {
pythonPathOverride = p
} else if (expectMidiBinaries) {
expectMidiBinariesError = true;
}
}
@ -30,6 +38,8 @@ class MidiConverter {
constructor() {
if (expectMidiBinariesError) MidiConverter.midiBinariesError()
this.py = new PythonShell('python/midi.py', Object.assign({
args: [
'--params',
@ -112,6 +122,8 @@ class MidiConverter {
static list() {
if (expectMidiBinariesError) MidiConverter.midiBinariesError()
PythonShell.run('python/midi.py', Object.assign({pythonPath: MidiConverter.getPythonPath(), args: ['--params', 'list-only']}, pythonOptions), function(e, results) {
if (e) {
if (e.code === 'ENOENT') {
@ -138,6 +150,14 @@ class MidiConverter {
}
static midiBinariesError() {
console.error(`(ERROR, MIDI) Could not find midi binary file ${p}\nIt may have been deleted by your antivirus.`)
console.log(`(INFO, MIDI) Falling back to python implementation (see https://openstagecontrol.ammd.net/docs/midi/midi-configuration/).`)
expectMidiBinariesError = false
}
}
module.exports = MidiConverter