diff options
-rw-r--r-- | ui.js | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/ui.js b/ui.js index 35bbec9..a327b98 100644 --- a/ui.js +++ b/ui.js @@ -25,8 +25,12 @@ const fs = require('fs') const { promisify } = require('util') const writeFile = promisify(fs.writeFile) -const playNow = Symbol() -const playIfNothingElse = Symbol() +// TODO: Come up with a better name for this +const Flags = { + playNow: Symbol(), + playIfNothingElse: Symbol(), + shuffleGroup: Symbol() +} class AppElement extends FocusElement { constructor() { @@ -125,8 +129,9 @@ class AppElement extends FocusElement { () => handleSelectFromMain(item))) grouplikeListing.on('play', item => this.playGrouplikeItem(item)) grouplikeListing.on('queue (at end)', item => this.queueGrouplikeItem(item)) - grouplikeListing.on('queue (shuffled)', item => this.shuffleQueueGrouplikeItem(item)) - grouplikeListing.on('queue (play next)', item => this.queueGrouplikeItem(item, playIfNothingElse, this.playingTrack)) + grouplikeListing.on('queue (at end, shuffled)', item => this.shuffleQueueGrouplikeItem(item)) + grouplikeListing.on('queue (play next)', item => this.queueGrouplikeItem(item, Flags.playIfNothingElse, this.playingTrack)) + grouplikeListing.on('queue (play next, shuffled)', item => this.shuffleQueueGrouplikeItem(item, Flags.playIfNothingElse, this.playingTrack)) grouplikeListing.on('menu', (item, opts) => this.menu.show(opts)) const updateListingsFor = item => { @@ -443,7 +448,7 @@ class AppElement extends FocusElement { this.player.kill() } - async queueGrouplikeItem(topItem, play = playIfNothingElse, afterItem = null) { + async queueGrouplikeItem(topItem, play = Flags.playIfNothingElse, afterItem = null) { const newTrackIndex = this.queueGrouplike.items.length const recursivelyAddTracks = item => { @@ -483,8 +488,8 @@ class AppElement extends FocusElement { // This is the first new track, if a group was queued. const newTrack = this.queueGrouplike.items[newTrackIndex] if ( - play === playNow || - (play === playIfNothingElse && !this.playingTrack && newTrack) + play === Flags.playNow || + (play === Flags.playIfNothingElse && !this.playingTrack && newTrack) ) { this.playGrouplikeItem(newTrack, false) } @@ -518,12 +523,12 @@ class AppElement extends FocusElement { this.queueListingElement.buildItems() } - shuffleQueueGrouplikeItem(item) { + shuffleQueueGrouplikeItem(item, ...rest) { if (!isGroup(item)) { return this.queueGrouplikeItem(item) } - return this.queueGrouplikeItem({items: shuffleArray(flattenGrouplike(item).items)}) + return this.queueGrouplikeItem({items: shuffleArray(flattenGrouplike(item).items)}, ...rest) } async downloadGrouplikeItem(item) { @@ -781,7 +786,7 @@ class GrouplikeListingElement extends FocusElement { if (this.grouplike.items.length) { for (const item of this.grouplike.items) { const itemElement = new GrouplikeItemElement(item, this.recordStore) - for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'play', 'queue (at end)', 'queue (shuffled)', 'queue (play next)', 'menu']) { + for (const evtName of ['download', 'remove (backspace)', 'remove (x)', 'mark', 'select (space)', 'select (enter)', 'play', 'queue (at end)', 'queue (at end, shuffled)', 'queue (play next)', 'queue (play next, shuffled)', 'menu']) { itemElement.on(evtName, (...data) => this.emit(evtName, item, ...data)) } form.addInput(itemElement) @@ -948,13 +953,9 @@ class GrouplikeItemElement extends Button { if (telc.isCaselessLetter(keyBuf, 'd')) { this.emit('download') } else if (telc.isCharacter(keyBuf, 'q')) { - this.emit('queue (at end)') + this.emit('queue (at end)') } else if (telc.isCharacter(keyBuf, 'Q')) { - if (isGroup(this.item)) { - this.emit('queue (shuffled)') - } else { - this.emit('queue (play next)') - } + this.emit('queue (play next)') } else if (telc.isSpace(keyBuf)) { this.emit('select (space)') } else if (telc.isEnter(keyBuf)) { @@ -975,7 +976,8 @@ class GrouplikeItemElement extends Button { {label: 'Play', action: () => this.emit('play')}, {label: 'Play next', action: () => this.emit('queue (play next)')}, {label: 'Play at end', action: () => this.emit('queue (at end)')}, - {label: 'Play at end, shuffled', action: () => this.emit('queue (shuffled)')} + {label: 'Play next, shuffled', action: () => this.emit('queue (play next, shuffled)')}, + {label: 'Play at end, shuffled', action: () => this.emit('queue (at end, shuffled)')} ] }) } |