2020-08-07 19:31:30 +02:00
|
|
|
class KeyHandler {
|
|
|
|
async init() {
|
|
|
|
await this.mediaKeys();
|
|
|
|
await this.addKeyHandler();
|
|
|
|
window.addEventListener('keydown', this.keyHandler.bind(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
async mediaKeys() {
|
|
|
|
if ('mediaSession' in navigator) {
|
|
|
|
let media = navigator.mediaSession;
|
|
|
|
media.setActionHandler('play', player.playStop.bind(player));
|
|
|
|
media.setActionHandler('pause', player.playStop.bind(player));
|
|
|
|
media.setActionHandler('previoustrack', player.prevSong.bind(player));
|
2020-08-08 21:58:15 +02:00
|
|
|
media.setActionHandler('nexttrack', player.nextSong.bind(player));
|
|
|
|
media.setActionHandler('stop', player.stop.bind(player));
|
2020-08-07 19:31:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async addKeyHandler() {
|
|
|
|
eventHandler.addEvent('keys-Space', player.playStop.bind(player));
|
|
|
|
eventHandler.addEvent('keys-KeyN', player.nextSong.bind(player));
|
|
|
|
eventHandler.addEvent('keys-KeyV', player.prevSong.bind(player));
|
|
|
|
eventHandler.addEvent('keys-KeyS', playerConf.open.bind(playerConf));
|
|
|
|
eventHandler.addEvent('keys-KeyS-shift', toggleShuffle);
|
|
|
|
eventHandler.addEvent('keys-KeyB', imageUploader.renderModal.bind(imageUploader));
|
|
|
|
eventHandler.addEvent('keys-KeyF-shift', forceAllRead);
|
|
|
|
eventHandler.addEvent('keys-KeyH', gui.openHelp);
|
|
|
|
eventHandler.addEvent('keys-KeyP', e => {
|
|
|
|
player.playlist.renderPagination(player.playlist.page);
|
|
|
|
gui.modal.showModal();
|
|
|
|
});
|
|
|
|
eventHandler.addEvent('keys-Escape, keys-KeyC-shift', e => {
|
|
|
|
gui.modal.resetModal();
|
|
|
|
gui.modal.closeModal();
|
|
|
|
})
|
|
|
|
eventHandler.addEvent('keys-F11', e => {
|
|
|
|
if (document.fullscreenElement) {
|
|
|
|
document.exitFullscreen().catch(console.error);
|
|
|
|
} else {
|
|
|
|
document.body.requestFullscreen().catch(console.error);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async keyHandler(event) {
|
|
|
|
let key = event.code,
|
|
|
|
shift = event.shiftKey ? '-shift' : '',
|
|
|
|
ctrl = event.ctrlKey ? '-ctrl' : '',
|
|
|
|
name = 'keys-' + key + shift + ctrl;
|
|
|
|
|
|
|
|
if (eventHandler.handleEvent({
|
|
|
|
data: {
|
2020-08-08 21:58:15 +02:00
|
|
|
cmd: name,
|
|
|
|
data: name
|
2020-08-07 19:31:30 +02:00
|
|
|
}
|
|
|
|
})) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|