Skip to content

Commit

Permalink
refactor: fullscreen logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ferferga authored Jun 12, 2023
1 parent 9ecd04a commit 7003649
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
5 changes: 0 additions & 5 deletions frontend/src/components/Playback/PiPVideoPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,11 @@

<script setup lang="ts">
import { onMounted, onBeforeUnmount } from 'vue';
import { useMagicKeys, whenever } from '@vueuse/core';
import { playbackManagerStore, playerElementStore } from '@/store';
const playerElement = playerElementStore();
const playbackManager = playbackManagerStore();
const keys = useMagicKeys();
whenever(keys.f, playerElement.toggleFullscreenVideoPlayer);
onMounted(() => {
playerElement.isPiPMounted = true;
});
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/composables/use-playerkeys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { whenever, useMagicKeys, noop } from '@vueuse/core';
import playbackManager from '@/store/playbackManager';
import { playbackManagerStore, playerElementStore } from '@/store';
import { isTizen, isWebOS } from '@/utils/browser-detection';

/**
Expand All @@ -9,6 +9,8 @@ import { isTizen, isWebOS } from '@/utils/browser-detection';
*/
export function usePlayerKeys(fullscreen = false, osdHandler = noop): void {
const keys = useMagicKeys();
const playbackManager = playbackManagerStore();
const playerElement = playerElementStore();
const forwardFn = (): void => {
playbackManager.skipForward();
osdHandler();
Expand All @@ -32,6 +34,8 @@ export function usePlayerKeys(fullscreen = false, osdHandler = noop): void {
whenever(keys.AudioVolumeUp, playbackManager.volumeUp);
whenever(keys.AudioVolumeDown, playbackManager.volumeDown);

whenever(keys.f, playerElement.toggleFullscreenPlayer);

if (fullscreen) {
whenever(keys.space, playbackManager.playPause);
whenever(keys.k, playbackManager.playPause);
Expand Down
23 changes: 20 additions & 3 deletions frontend/src/store/playerElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,33 @@ class PlayerElementStore {
return useRouter().currentRoute.value.fullPath === fullscreenVideoRoute;
}

public get isFullscreenMusicPlayer(): boolean {
return useRouter().currentRoute.value.fullPath === fullscreenMusicRoute;
}

public get isFullscreenPlayer(): boolean {
return this.isFullscreenMusicPlayer || this.isFullscreenVideoPlayer;
}

/**
* == ACTIONS ==
*/
public toggleFullscreenVideoPlayer = async (): Promise<void> => {
public toggleFullscreenPlayer = async (): Promise<void> => {
const router = useRouter();

if (this.isFullscreenVideoPlayer) {
if (this.isFullscreenPlayer) {
router.back();
} else {
await router.push(fullscreenVideoRoute);
switch (playbackManager.currentlyPlayingMediaType) {
case 'Video': {
await router.push(fullscreenVideoRoute);
break;
}
case 'Audio': {
await router.push(fullscreenMusicRoute);
break;
}
}
}
};

Expand Down

0 comments on commit 7003649

Please sign in to comment.