Skip to content

Commit

Permalink
Replace in-code use of available shortcuts with the corresponding con…
Browse files Browse the repository at this point in the history
…stants
  • Loading branch information
kommunarr committed Oct 13, 2024
1 parent 3134053 commit 24b233d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2006,55 +2006,47 @@ export default defineComponent({

const video_ = video.value

switch (event.key) {
switch (event.key.toLowerCase()) {
case ' ':
case 'Spacebar': // older browsers might return spacebar instead of a space character
case 'K':
case 'k':
case 'spacebar': // older browsers might return spacebar instead of a space character
case KeyboardShortcuts.VIDEO_PLAYER.PLAY:
// Toggle Play/Pause
event.preventDefault()
video_.paused ? video_.play() : video_.pause()
break
case 'J':
case 'j':
case KeyboardShortcuts.VIDEO_PLAYER.LARGE_REWIND:
// Rewind by 2x the time-skip interval (in seconds)
event.preventDefault()
seekBySeconds(-defaultSkipInterval.value * video_.playbackRate * 2)
break
case 'L':
case 'l':
case KeyboardShortcuts.VIDEO_PLAYER.LARGE_FAST_FORWARD:
// Fast-Forward by 2x the time-skip interval (in seconds)
event.preventDefault()
seekBySeconds(defaultSkipInterval.value * video_.playbackRate * 2)
break
case 'O':
case 'o':
case KeyboardShortcuts.VIDEO_PLAYER.DECREASE_VIDEO_SPEED:
// Decrease playback rate by user configured interval
event.preventDefault()
changePlayBackRate(-videoPlaybackRateInterval.value)
break
case 'P':
case 'p':
case KeyboardShortcuts.VIDEO_PLAYER.INCREASE_VIDEO_SPEED:
// Increase playback rate by user configured interval
event.preventDefault()
changePlayBackRate(videoPlaybackRateInterval.value)
break
case 'F':
case 'f':
case KeyboardShortcuts.VIDEO_PLAYER.FULLSCREEN:
// Toggle full screen
event.preventDefault()
ui.getControls().toggleFullScreen()
break
case 'M':
case 'm':
case KeyboardShortcuts.VIDEO_PLAYER.MUTE:
// Toggle mute only if metakey is not pressed
if (!event.metaKey) {
event.preventDefault()
video_.muted = !video_.muted
}
break
case 'C':
case 'c':
case KeyboardShortcuts.VIDEO_PLAYER.SUBTITLES:
// Toggle caption/subtitles
if (player.getTextTracks().length > 0) {
event.preventDefault()
Expand All @@ -2063,17 +2055,17 @@ export default defineComponent({
player.setTextTrackVisibility(!currentlyVisible)
}
break
case 'ArrowUp':
case 'arrowup':
// Increase volume
event.preventDefault()
changeVolume(0.05)
break
case 'ArrowDown':
case 'arrowdown':
// Decrease Volume
event.preventDefault()
changeVolume(-0.05)
break
case 'ArrowLeft':
case 'arrowleft':
event.preventDefault()
if (canChapterJump(event, 'previous')) {
// Jump to the previous chapter
Expand All @@ -2083,7 +2075,7 @@ export default defineComponent({
seekBySeconds(-defaultSkipInterval.value * video_.playbackRate)
}
break
case 'ArrowRight':
case 'arrowright':
event.preventDefault()
if (canChapterJump(event, 'next')) {
// Jump to the next chapter
Expand All @@ -2093,8 +2085,7 @@ export default defineComponent({
seekBySeconds(defaultSkipInterval.value * video_.playbackRate)
}
break
case 'I':
case 'i':
case KeyboardShortcuts.VIDEO_PLAYER.PICTURE_IN_PICTURE:
// Toggle picture in picture
if (props.format !== 'audio') {
const controls = ui.getControls()
Expand Down Expand Up @@ -2127,26 +2118,25 @@ export default defineComponent({
}
break
}
case ',':
case KeyboardShortcuts.VIDEO_PLAYER.LAST_FRAME:
event.preventDefault()
// Return to previous frame
frameByFrame(-1)
break
case '.':
case KeyboardShortcuts.VIDEO_PLAYER.NEXT_FRAME:
event.preventDefault()
// Advance to next frame
frameByFrame(1)
break
case 'D':
case 'd':
case KeyboardShortcuts.VIDEO_PLAYER.STATS:
// Toggle stats display
event.preventDefault()

events.dispatchEvent(new CustomEvent('setStatsVisibility', {
detail: !showStats.value
}))
break
case 'Escape':
case 'escape':
// Exit full window
if (fullWindowEnabled.value) {
event.preventDefault()
Expand All @@ -2156,16 +2146,14 @@ export default defineComponent({
}))
}
break
case 'S':
case 's':
case KeyboardShortcuts.VIDEO_PLAYER.FULLWINDOW:
// Toggle full window mode
event.preventDefault()
events.dispatchEvent(new CustomEvent('setFullWindow', {
detail: !fullWindowEnabled.value
}))
break
case 'T':
case 't':
case KeyboardShortcuts.VIDEO_PLAYER.THEATRE_MODE:
// Toggle theatre mode
if (props.theatrePossible) {
event.preventDefault()
Expand All @@ -2175,8 +2163,7 @@ export default defineComponent({
}))
}
break
case 'U':
case 'u':
case KeyboardShortcuts.VIDEO_PLAYER.TAKE_SCREENSHOT:
if (process.env.IS_ELECTRON && enableScreenshot.value && props.format !== 'audio') {
event.preventDefault()
// Take screenshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
import FtElementList from '../FtElementList/FtElementList.vue'
import FtChannelBubble from '../ft-channel-bubble/ft-channel-bubble.vue'
import FtAutoLoadNextPageWrapper from '../ft-auto-load-next-page-wrapper/ft-auto-load-next-page-wrapper.vue'
import { KeyboardShortcuts } from '../../../constants'

export default defineComponent({
name: 'SubscriptionsTabUI',
Expand Down Expand Up @@ -114,9 +115,8 @@ export default defineComponent({
if (event.repeat) { return }

switch (event.key) {
case 'r':
case 'R':
case 'F5':
case KeyboardShortcuts.FEED.REFRESH:
if (!this.isLoading && this.activeSubscriptionList.length > 0) {
this.$emit('refresh')
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/views/Popular/Popular.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import FtRefreshWidget from '../../components/ft-refresh-widget/ft-refresh-widge

import { invidiousAPICall } from '../../helpers/api/invidious'
import { copyToClipboard, getRelativeTimeFromDate, setPublishedTimestampsInvidious, showToast } from '../../helpers/utils'
import { KeyboardShortcuts } from '../../../constants'

export default defineComponent({
name: 'Popular',
Expand Down Expand Up @@ -90,10 +91,9 @@ export default defineComponent({
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat
if (event.repeat) { return }

switch (event.key) {
case 'r':
case 'R':
case 'F5':
switch (event.key.toLowerCase()) {
case 'f5':
case KeyboardShortcuts.FEED.REFRESH:
if (!this.isLoading) {
this.fetchPopularInfo()
}
Expand Down
8 changes: 4 additions & 4 deletions src/renderer/views/Trending/Trending.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import FtRefreshWidget from '../../components/ft-refresh-widget/ft-refresh-widge
import { copyToClipboard, getRelativeTimeFromDate, setPublishedTimestampsInvidious, showToast } from '../../helpers/utils'
import { getLocalTrending } from '../../helpers/api/local'
import { invidiousAPICall } from '../../helpers/api/invidious'
import { KeyboardShortcuts } from '../../../constants'

export default defineComponent({
name: 'Trending',
Expand Down Expand Up @@ -189,10 +190,9 @@ export default defineComponent({
// https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat
if (event.repeat) { return }

switch (event.key) {
case 'r':
case 'R':
case 'F5':
switch (event.key.toLowerCase()) {
case 'f5':
case KeyboardShortcuts.FEED.REFRESH:
if (!this.isLoading) {
this.getTrendingInfo(true)
}
Expand Down

0 comments on commit 24b233d

Please sign in to comment.