From 47bd859d1a02683395bbf941d7dc0375d7ef8334 Mon Sep 17 00:00:00 2001 From: Florrie Date: Tue, 10 Sep 2019 12:23:41 -0300 Subject: 'Clear past / up to this track' queue menu options --- backend.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'backend.js') diff --git a/backend.js b/backend.js index 0ddd15b..57910e9 100644 --- a/backend.js +++ b/backend.js @@ -316,6 +316,37 @@ class Backend extends EventEmitter { return focusItem } + clearQueuePast(track) { + const { items } = this.queueGrouplike + const index = items.indexOf(track) + 1 + + if (index < 0) { + return + } else if (index < items.indexOf(this.playingTrack)) { + items.splice(index, items.length - index, this.playingTrack) + } else { + items.splice(index) + } + + this.emitQueueUpdated() + } + + clearQueueUpTo(track) { + const { items } = this.queueGrouplike + const endIndex = items.indexOf(track) + const startIndex = (this.playingTrack ? items.indexOf(this.playingTrack) + 1 : 0) + + if (endIndex < 0) { + return + } else if (endIndex < startIndex) { + return + } else { + items.splice(startIndex, endIndex - startIndex) + } + + this.emitQueueUpdated() + } + playSooner(item) { this.distributeQueue(item, { how: 'randomly', -- cgit 1.3.0-6-gf8a5