feat: repeat mode shortcut

This commit is contained in:
Phan An 2024-03-18 18:56:17 +01:00
parent b8bfd37964
commit e29c1b6008
6 changed files with 6 additions and 8 deletions

View file

@ -137,6 +137,7 @@ or a textarea.
* <kbd>j</kbd> plays the next song in queue
* <kbd>k</kbd> plays the previous song in queue
* <kbd>l</kbd> marks/unmarks the current song as favorite
* <kbd>r</kbd> circles through repeat modes (no repeat, repeat all, repeat one)
* <kbd></kbd> seeks forward 10 seconds
* <kbd></kbd> seeks backward 10 seconds
* <kbd></kbd> increases volume by 10%

View file

@ -8,7 +8,7 @@ import RepeatModeSwitch from './RepeatModeSwitch.vue'
new class extends UnitTestCase {
protected test () {
it('changes mode', async () => {
const mock = this.mock(playbackService, 'changeRepeatMode')
const mock = this.mock(playbackService, 'rotateRepeatMode')
preferenceStore.state.repeat_mode = 'NO_REPEAT'
this.render(RepeatModeSwitch)

View file

@ -29,7 +29,7 @@ const readableMode = computed(() => mode.value
.join(' ')
)
const changeMode = () => playbackService.changeRepeatMode()
const changeMode = () => playbackService.rotateRepeatMode()
</script>
<style lang="scss" scoped>

View file

@ -20,6 +20,7 @@ onKeyStroke('f', () => eventBus.emit('FOCUS_SEARCH_FIELD'))
onKeyStroke('j', () => playbackService.playNext())
onKeyStroke('k', () => playbackService.playPrev())
onKeyStroke(' ', () => playbackService.toggle())
onKeyStroke('r', () => playbackService.rotateRepeatMode())
onKeyStroke('ArrowRight', () => playbackService.seekBy(10))
onKeyStroke('ArrowLeft', () => playbackService.seekBy(-10))

View file

@ -220,7 +220,7 @@ new class extends UnitTestCase {
])('it switches from repeat mode %s to repeat mode %s', (fromMode, toMode) => {
playbackService.init(document.querySelector('.plyr')!)
preferences.repeat_mode = fromMode
playbackService.changeRepeatMode()
playbackService.rotateRepeatMode()
expect(preferences.repeat_mode).toEqual(toMode)
})

View file

@ -199,11 +199,7 @@ class PlaybackService {
}
}
/**
* Circle through the repeat mode.
* The selected mode will be stored into local storage as well.
*/
public changeRepeatMode () {
public rotateRepeatMode () {
let index = this.repeatModes.indexOf(preferences.repeat_mode) + 1
if (index >= this.repeatModes.length) {