From 3c0cd5c2a98685ab9fd0fdf97a1ac28ceb97dc74 Mon Sep 17 00:00:00 2001 From: Florrie Date: Wed, 13 Jun 2018 21:03:30 -0300 Subject: Error handling stuff --- index.js | 26 ++++++++++++++------------ todo.txt | 2 ++ ui.js | 9 +++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index b1c4ced..3abbe83 100755 --- a/index.js +++ b/index.js @@ -29,12 +29,6 @@ async function main() { const interfacer = new CommandLineInterfacer() const size = await interfacer.getScreenSize() - const flushable = new Flushable(process.stdout, true) - flushable.resizeScreen(size) - flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats') - flushable.write(ansi.clearScreen()) - flushable.flush() - const root = new Root(interfacer) root.w = size.width root.h = size.height @@ -50,7 +44,12 @@ async function main() { root.addChild(appElement) root.select(appElement) - await appElement.setup() + const result = await appElement.setup() + + if (result.error) { + console.error(result.error) + process.exit(1) + } appElement.on('quitRequested', () => { process.stdout.write(ansi.cleanCursor()) @@ -66,16 +65,13 @@ async function main() { } if (process.argv[2]) { - flushable.write(ansi.moveCursor(0, 0)) - flushable.write('Opening playlist...') - flushable.flush() + console.log('Opening playlist...') let grouplikeText try { grouplikeText = await readFile(process.argv[2]) } catch (error) { - flushable.write('Error opening the passed file "' + process.argv[2] + '"!') - flushable.flush() + console.error('Error opening the passed file "' + process.argv[2] + '"!') process.exit(1) } @@ -94,6 +90,12 @@ async function main() { root.select(appElement.form) + const flushable = new Flushable(process.stdout, true) + flushable.resizeScreen(size) + flushable.shouldShowCompressionStatistics = process.argv.includes('--show-ansi-stats') + flushable.write(ansi.clearScreen()) + flushable.flush() + setInterval(() => { root.renderTo(flushable) flushable.flush() diff --git a/todo.txt b/todo.txt index e190b31..c008d46 100644 --- a/todo.txt +++ b/todo.txt @@ -27,3 +27,5 @@ TODO: Pressing enter in the queue seems to not be doing the right thing? (Done!) TODO: iTunes downloader - test this. + +TODO: Warn if no mkfifo (means controls won't work). diff --git a/ui.js b/ui.js index ac86a47..371958d 100644 --- a/ui.js +++ b/ui.js @@ -95,9 +95,18 @@ class AppElement extends FocusElement { async setup() { this.player = await getPlayer() + + if (!this.player) { + return { + error: "Sorry, it doesn't look like there's an audio player installed on your computer. Can you try installing MPV (https://mpv.io) or SoX?" + } + } + this.player.on('printStatusLine', data => { this.playbackInfoElement.updateProgress(data) }) + + return true } async shutdown() { -- cgit 1.3.0-6-gf8a5