From 08a3150fe9c9427bdb9e46d0cde14ad30747008d Mon Sep 17 00:00:00 2001 From: Florrie Date: Fri, 5 Jul 2019 21:10:32 -0300 Subject: Separate backend from UI --- index.js | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'index.js') 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) -- cgit 1.3.0-6-gf8a5