diff options
Diffstat (limited to 'index.js')
-rwxr-xr-x | index.js | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/index.js b/index.js index 578fdc3..23d0449 100755 --- a/index.js +++ b/index.js @@ -2,19 +2,31 @@ // omg I am tired of code -const { AppElement } = require('./ui') -const { updatePlaylistFormat } = require('./playlist-utils') const { getAllCrawlersForArg } = require('./crawlers') -const fs = require('fs') -const util = require('util') +const AppElement = require('./ui') +const Backend = require('./backend') const processSmartPlaylist = require('./smart-playlist') -const ansi = require('./tui-lib/util/ansi') -const CommandLineInterfacer = require('./tui-lib/util/CommandLineInterfacer') -const EventEmitter = require('events') -const Flushable = require('./tui-lib/util/Flushable') -const Root = require('./tui-lib/ui/Root') -const readFile = util.promisify(fs.readFile) +const { + getItemPathString, + updatePlaylistFormat +} = require('./playlist-utils') + +const { + ui: { + Root + }, + util: { + ansi, + CommandLineInterfacer, + Flushable + } +} = require('./tui-lib') + +const { promisify } = require('util') +const fs = require('fs') +const readFile = promisify(fs.readFile) +const writeFile = promisify(fs.writeFile) // Hack to get around errors when piping many things to stdout/err // (from general-util promisifyProcess) @@ -40,11 +52,22 @@ async function main() { const root = new Root(interfacer) - const appElement = new AppElement() + const backend = new Backend() + + backend.on('playing', track => { + if (track) { + writeFile(backend.rootDirectory + '/current-track.txt', + getItemPathString(track)) + writeFile(backend.rootDirectory + '/current-track.json', + JSON.stringify(track, null, 2)) + } + }) + + const appElement = new AppElement(backend) root.addChild(appElement) root.select(appElement) - const result = await appElement.setup() + const result = await backend.setup() if (result.error) { console.error(result.error) |