From 0ca5fa4e03916621afe8894c55524f3393ec0c60 Mon Sep 17 00:00:00 2001 From: Jeremias Volker Date: Mon, 23 Sep 2019 19:30:45 +0200 Subject: [PATCH] Adds option to pass functions to the `end_command` in extensions. Closes #43 --- src/controller.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/controller.js b/src/controller.js index 11737a3..d3706cf 100755 --- a/src/controller.js +++ b/src/controller.js @@ -307,7 +307,7 @@ fc.changeArtwork = function() { function swapArt() { debug('swapArt'); if (old_artwork) { - _endArt(old_format.end_command, old_artwork) + _endArt(old_format, old_artwork) .then(function() { _startArt(new_format, new_artwork).then(function() { fc.current_artwork = new_artwork; @@ -421,14 +421,23 @@ function _startArt(new_format, new_artwork) { /** * End a playing artwork. - * @param {string} _command + * @param {string} old_format * @param {object} old_artwork * @return {Promise} Resolves when command is complete. */ -function _endArt(_command, old_artwork) { +function _endArt(old_format, old_artwork) { debug('endArt'); - var tokens = old_artwork.tokens || {}, - command = _replaceTokens(_command, tokens); + var _command = old_format.end_command, + tokens = old_artwork.tokens || {}; + if (typeof _command === 'function') { + + // we're passing artwork-specific args and tokens here, letting the format + // construct the command dynamically... + var settings = old_artwork.settings || {}; + _command = _command.call(old_format, settings, tokens); + } + var command = _replaceTokens(_command, tokens); + return new Promise(function(resolve, reject) { proc_man.exec(command, function(err) { if (err) {