Skip to content

Commit

Permalink
Merge branch 'feat/add-shortcut-labels' of github.com:kommunarr/FreeT…
Browse files Browse the repository at this point in the history
…ube into feat/add-shortcut-labels
  • Loading branch information
kommunarr committed Nov 23, 2024
2 parents 89b6861 + 348100d commit fdae9b4
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 82 deletions.
65 changes: 34 additions & 31 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,41 +116,44 @@ const SyncEvents = {
// note: the multi-key shortcut values are currently just for display use in action titles
const KeyboardShortcuts = {
APP: {
HISTORY_BACKWARD: 'alt+arrowleft',
HISTORY_FORWARD: 'alt+arrowright',
NEW_WINDOW: 'ctrl+N',
NAVIGATE_TO_SETTINGS: 'ctrl+,',
NAVIGATE_TO_HISTORY: 'ctrl+H',
NAVIGATE_TO_HISTORY_MAC: 'cmd+Y',
},
FEED: {
REFRESH: 'r'
GENERAL: {
HISTORY_BACKWARD: 'alt+arrowleft',
HISTORY_FORWARD: 'alt+arrowright',
NEW_WINDOW: 'ctrl+N',
NAVIGATE_TO_SETTINGS: 'ctrl+,',
NAVIGATE_TO_HISTORY: 'ctrl+H',
NAVIGATE_TO_HISTORY_MAC: 'cmd+Y',
},
SITUATIONAL: {
REFRESH: 'r'
},
},
VIDEO_PLAYER: {
CAPTIONS: 'c',
STATS: 'd',
FULLSCREEN: 'f',
PICTURE_IN_PICTURE: 'i',
LARGE_REWIND: 'j',
PLAY: 'k',
LARGE_FAST_FORWARD: 'l',
MUTE: 'm',
DECREASE_VIDEO_SPEED: 'o',
INCREASE_VIDEO_SPEED: 'p',
FULLWINDOW: 's',
THEATRE_MODE: 't',
TAKE_SCREENSHOT: 'u',
LAST_FRAME: ',',
NEXT_FRAME: '.',
VOLUME_UP: 'arrowup',
VOLUME_DOWN: 'arrowdown',
SMALL_REWIND: 'arrowleft',
SMALL_FAST_FORWARD: 'arrowright',

/* For future use
GENERAL: {
CAPTIONS: 'c',
THEATRE_MODE: 't',
FULLSCREEN: 'f',
FULLWINDOW: 's',
PICTURE_IN_PICTURE: 'i',
MUTE: 'm',
VOLUME_UP: 'arrowup',
VOLUME_DOWN: 'arrowdown',
STATS: 'd',
TAKE_SCREENSHOT: 'u',
},
PLAYBACK: {
PLAY: 'k',
LARGE_REWIND: 'j',
LARGE_FAST_FORWARD: 'l',
SMALL_REWIND: 'arrowleft',
SMALL_FAST_FORWARD: 'arrowright',
DECREASE_VIDEO_SPEED: 'o',
INCREASE_VIDEO_SPEED: 'p',
LAST_FRAME: ',',
NEXT_FRAME: '.',
LAST_CHAPTER: 'ctrl+arrowleft',
NEXT_CHAPTER: 'ctrl+arrowright',
*/
}
},
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export default defineComponent({
refreshFeedButtonTitle: function() {
return addKeyboardShortcutToActionTitle(
this.$t('Feed.Refresh Feed', { subscriptionName: this.title }),
KeyboardShortcuts.FEED.REFRESH
KeyboardShortcuts.APP.SITUATIONAL.REFRESH
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ const AdvancedRequestType = shaka.net.NetworkingEngine.AdvancedRequestType
const TrackLabelFormat = shaka.ui.Overlay.TrackLabelFormat

const shakaControlKeysToShortcuts = {
MUTE: KeyboardShortcuts.VIDEO_PLAYER.MUTE,
UNMUTE: KeyboardShortcuts.VIDEO_PLAYER.MUTE,
PLAY: KeyboardShortcuts.VIDEO_PLAYER.PLAY,
PAUSE: KeyboardShortcuts.VIDEO_PLAYER.PLAY,
PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.PICTURE_IN_PICTURE,
ENTER_PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.PICTURE_IN_PICTURE,
EXIT_PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.PICTURE_IN_PICTURE,
CAPTIONS: KeyboardShortcuts.VIDEO_PLAYER.CAPTIONS,
FULL_SCREEN: KeyboardShortcuts.VIDEO_PLAYER.FULLSCREEN,
EXIT_FULL_SCREEN: KeyboardShortcuts.VIDEO_PLAYER.FULLSCREEN
MUTE: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.MUTE,
UNMUTE: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.MUTE,
PLAY: KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.PLAY,
PAUSE: KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.PLAY,
PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.PICTURE_IN_PICTURE,
ENTER_PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.PICTURE_IN_PICTURE,
EXIT_PICTURE_IN_PICTURE: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.PICTURE_IN_PICTURE,
CAPTIONS: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.CAPTIONS,
FULL_SCREEN: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLSCREEN,
EXIT_FULL_SCREEN: KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLSCREEN
}

/** @type {Map<string, string>} */
Expand Down Expand Up @@ -1997,44 +1997,44 @@ export default defineComponent({
switch (event.key.toLowerCase()) {
case ' ':
case 'spacebar': // older browsers might return spacebar instead of a space character
case KeyboardShortcuts.VIDEO_PLAYER.PLAY:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.PLAY:
// Toggle Play/Pause
event.preventDefault()
video_.paused ? video_.play() : video_.pause()
break
case KeyboardShortcuts.VIDEO_PLAYER.LARGE_REWIND:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.LARGE_REWIND:
// Rewind by 2x the time-skip interval (in seconds)
event.preventDefault()
seekBySeconds(-defaultSkipInterval.value * video_.playbackRate * 2)
break
case KeyboardShortcuts.VIDEO_PLAYER.LARGE_FAST_FORWARD:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.LARGE_FAST_FORWARD:
// Fast-Forward by 2x the time-skip interval (in seconds)
event.preventDefault()
seekBySeconds(defaultSkipInterval.value * video_.playbackRate * 2)
break
case KeyboardShortcuts.VIDEO_PLAYER.DECREASE_VIDEO_SPEED:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.DECREASE_VIDEO_SPEED:
// Decrease playback rate by user configured interval
event.preventDefault()
changePlayBackRate(-videoPlaybackRateInterval.value)
break
case KeyboardShortcuts.VIDEO_PLAYER.INCREASE_VIDEO_SPEED:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.INCREASE_VIDEO_SPEED:
// Increase playback rate by user configured interval
event.preventDefault()
changePlayBackRate(videoPlaybackRateInterval.value)
break
case KeyboardShortcuts.VIDEO_PLAYER.FULLSCREEN:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLSCREEN:
// Toggle full screen
event.preventDefault()
ui.getControls().toggleFullScreen()
break
case KeyboardShortcuts.VIDEO_PLAYER.MUTE:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.MUTE:
// Toggle mute only if metakey is not pressed
if (!event.metaKey) {
event.preventDefault()
video_.muted = !video_.muted
}
break
case KeyboardShortcuts.VIDEO_PLAYER.CAPTIONS:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.CAPTIONS:
// Toggle caption/subtitles
if (player.getTextTracks().length > 0) {
event.preventDefault()
Expand All @@ -2043,17 +2043,17 @@ export default defineComponent({
player.setTextTrackVisibility(!currentlyVisible)
}
break
case KeyboardShortcuts.VIDEO_PLAYER.VOLUME_UP:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.VOLUME_UP:
// Increase volume
event.preventDefault()
changeVolume(0.05)
break
case KeyboardShortcuts.VIDEO_PLAYER.VOLUME_DOWN:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.VOLUME_DOWN:
// Decrease Volume
event.preventDefault()
changeVolume(-0.05)
break
case KeyboardShortcuts.VIDEO_PLAYER.SMALL_REWIND:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.SMALL_REWIND:
event.preventDefault()
if (canChapterJump(event, 'previous')) {
// Jump to the previous chapter
Expand All @@ -2063,7 +2063,7 @@ export default defineComponent({
seekBySeconds(-defaultSkipInterval.value * video_.playbackRate)
}
break
case KeyboardShortcuts.VIDEO_PLAYER.SMALL_FAST_FORWARD:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.SMALL_FAST_FORWARD:
event.preventDefault()
if (canChapterJump(event, 'next')) {
// Jump to the next chapter
Expand All @@ -2073,7 +2073,7 @@ export default defineComponent({
seekBySeconds(defaultSkipInterval.value * video_.playbackRate)
}
break
case KeyboardShortcuts.VIDEO_PLAYER.PICTURE_IN_PICTURE:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.PICTURE_IN_PICTURE:
// Toggle picture in picture
if (props.format !== 'audio') {
const controls = ui.getControls()
Expand Down Expand Up @@ -2106,20 +2106,20 @@ export default defineComponent({
}
break
}
case KeyboardShortcuts.VIDEO_PLAYER.LAST_FRAME:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.LAST_FRAME:
// `⌘+,` is for settings in MacOS
if (!event.metaKey) {
event.preventDefault()
// Return to previous frame
frameByFrame(-1)
}
break
case KeyboardShortcuts.VIDEO_PLAYER.NEXT_FRAME:
case KeyboardShortcuts.VIDEO_PLAYER.PLAYBACK.NEXT_FRAME:
event.preventDefault()
// Advance to next frame
frameByFrame(1)
break
case KeyboardShortcuts.VIDEO_PLAYER.STATS:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.STATS:
// Toggle stats display
event.preventDefault()

Expand All @@ -2137,14 +2137,14 @@ export default defineComponent({
}))
}
break
case KeyboardShortcuts.VIDEO_PLAYER.FULLWINDOW:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLWINDOW:
// Toggle full window mode
event.preventDefault()
events.dispatchEvent(new CustomEvent('setFullWindow', {
detail: !fullWindowEnabled.value
}))
break
case KeyboardShortcuts.VIDEO_PLAYER.THEATRE_MODE:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.THEATRE_MODE:
// Toggle theatre mode
if (props.theatrePossible) {
event.preventDefault()
Expand All @@ -2154,7 +2154,7 @@ export default defineComponent({
}))
}
break
case KeyboardShortcuts.VIDEO_PLAYER.TAKE_SCREENSHOT:
case KeyboardShortcuts.VIDEO_PLAYER.GENERAL.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 @@ -75,7 +75,7 @@ export class FullWindowButton extends shaka.ui.Element {
const baseAriaLabel = this.fullWindowEnabled_ ? i18n.t('Video.Player.Exit Full Window') : i18n.t('Video.Player.Full Window')
const newLabel = addKeyboardShortcutToActionTitle(
baseAriaLabel,
KeyboardShortcuts.VIDEO_PLAYER.FULLWINDOW
KeyboardShortcuts.VIDEO_PLAYER.GENERAL.FULLWINDOW
)
this.nameSpan_.textContent = this.button_.ariaLabel = newLabel
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class ScreenshotButton extends shaka.ui.Element {
updateLocalisedStrings_() {
const label = addKeyboardShortcutToActionTitle(
i18n.t('Video.Player.Take Screenshot'),
KeyboardShortcuts.VIDEO_PLAYER.TAKE_SCREENSHOT
KeyboardShortcuts.VIDEO_PLAYER.GENERAL.TAKE_SCREENSHOT
)
this.nameSpan_.textContent = this.button_.ariaLabel = label
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class StatsButton extends shaka.ui.Element {
const baseLabel = this.showStats_ ? i18n.t('Video.Player.Hide Stats') : i18n.t('Video.Player.Show Stats')
const label = addKeyboardShortcutToActionTitle(
baseLabel,
KeyboardShortcuts.VIDEO_PLAYER.STATS
KeyboardShortcuts.VIDEO_PLAYER.GENERAL.STATS
)

this.currentState_.textContent = label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class TheatreModeButton extends shaka.ui.Element {

this.nameSpan_.textContent = this.button_.ariaLabel = addKeyboardShortcutToActionTitle(
baseAriaLabel,
KeyboardShortcuts.VIDEO_PLAYER.THEATRE_MODE
KeyboardShortcuts.VIDEO_PLAYER.GENERAL.THEATRE_MODE
)
}
}
6 changes: 3 additions & 3 deletions src/renderer/components/side-nav/side-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export default defineComponent({
},
historyTitle: function() {
const shortcut = process.platform === 'darwin'
? KeyboardShortcuts.APP.NAVIGATE_TO_HISTORY_MAC
: KeyboardShortcuts.APP.NAVIGATE_TO_HISTORY
? KeyboardShortcuts.APP.GENERAL.NAVIGATE_TO_HISTORY_MAC
: KeyboardShortcuts.APP.GENERAL.NAVIGATE_TO_HISTORY

return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('History.History'),
Expand All @@ -95,7 +95,7 @@ export default defineComponent({
settingsTitle: function() {
return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Settings.Settings'),
KeyboardShortcuts.APP.NAVIGATE_TO_SETTINGS
KeyboardShortcuts.APP.GENERAL.NAVIGATE_TO_SETTINGS
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default defineComponent({

switch (event.key.toLowerCase()) {
case 'f5':
case KeyboardShortcuts.FEED.REFRESH:
case KeyboardShortcuts.APP.SITUATIONAL.REFRESH:
if (!this.isLoading && this.activeSubscriptionList.length > 0) {
this.$emit('refresh')
}
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/components/top-nav/top-nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ export default defineComponent({
forwardText: function () {
return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Forward'),
KeyboardShortcuts.APP.HISTORY_FORWARD
KeyboardShortcuts.APP.GENERAL.HISTORY_FORWARD
)
},

backwardText: function () {
return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Back'),
KeyboardShortcuts.APP.HISTORY_BACKWARD
KeyboardShortcuts.APP.GENERAL.HISTORY_BACKWARD
)
},

newWindowText: function () {
return localizeAndAddKeyboardShortcutToActionTitle(
this.$t('Open New Window'),
KeyboardShortcuts.APP.NEW_WINDOW
KeyboardShortcuts.APP.GENERAL.NEW_WINDOW
)
}
},
Expand Down
Loading

0 comments on commit fdae9b4

Please sign in to comment.