Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base shortcuts #517

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,42 @@ onMounted(() => {
window
.matchMedia('(prefers-color-scheme: dark)')
.addEventListener('change', setTheme);

const handleKeyDown = (e: KeyboardEvent) => {
if (api.state.value === ConnectionState.CONNECTED) {
//Ensure the api can communicate with the server
if (!store.activePlayerQueue?.active) {
//Ensure a player is active
const key = e.key;
let keyDetected = true;

max246 marked this conversation as resolved.
Show resolved Hide resolved
if (store.activePlayerQueue && store.activePlayerQueue.active) {
//Ensure queue is active to interact with
if (key === 'MediaPlayPause' || key === 'Space')
api.queueCommandPlayPause(store.activePlayerQueue!.queue_id);
if (key === 'MediaStop')
api.queueCommandStop(store.activePlayerQueue!.queue_id);
if (key === 'MediaTrackPrevious')
api.queueCommandPrevious(store.activePlayerQueue!.queue_id);
if (key === 'MediaTrackNext')
api.queueCommandNext(store.activePlayerQueue!.queue_id);
} else if (key === 'AudioVolumeUp')
api.playerCommandVolumeUp(store.activePlayer?.player_id || '');
else if (key === 'AudioVolumeDown')
api.playerCommandVolumeDown(store.activePlayer?.player_id || '');
else if (key === 'AudioVolumeMute')
api.playerCommandVolumeMute(
store.activePlayer?.player_id || '',
!store.activePlayer?.volume_muted || false,
);
else keyDetected = false;

if (keyDetected) e.preventDefault();
}
}
};

window.addEventListener('keydown', handleKeyDown, true);
// Initialize API Connection
// TODO: retrieve serveraddress through discovery and/or user settings ?
let serverAddress = '';
Expand Down