Skip to content

Commit b934703

Browse files
committed
Add labels for History and Settings app shortcuts, and update variable naming
1 parent 6798c3a commit b934703

File tree

11 files changed

+61
-26
lines changed

11 files changed

+61
-26
lines changed

src/constants.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,10 @@ const KeyboardShortcuts = {
118118
APP: {
119119
HISTORY_BACKWARD: 'alt+arrowleft',
120120
HISTORY_FORWARD: 'alt+arrowright',
121-
NEW_WINDOW: 'ctrl+N'
121+
NEW_WINDOW: 'ctrl+N',
122+
NAVIGATE_TO_SETTINGS: 'ctrl+,',
123+
NAVIGATE_TO_HISTORY: 'ctrl+H',
124+
NAVIGATE_TO_HISTORY_MAC: 'cmd+Y',
122125
},
123126
FEED: {
124127
REFRESH: 'r'

src/renderer/components/ft-refresh-widget/ft-refresh-widget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineComponent } from 'vue'
22

33
import FtIconButton from '../ft-icon-button/ft-icon-button.vue'
44
import { KeyboardShortcuts } from '../../../constants'
5-
import { addKeyboardShortcutToActionLabel } from '../../helpers/utils'
5+
import { addKeyboardShortcutToActionTitle } from '../../helpers/utils'
66

77
export default defineComponent({
88
name: 'FtRefreshWidget',
@@ -26,7 +26,7 @@ export default defineComponent({
2626
emits: ['click'],
2727
computed: {
2828
refreshFeedButtonTitle: function() {
29-
return addKeyboardShortcutToActionLabel(
29+
return addKeyboardShortcutToActionTitle(
3030
this.$t('Feed.Refresh Feed', { subscriptionName: this.title }),
3131
KeyboardShortcuts.FEED.REFRESH
3232
)

src/renderer/components/ft-shaka-video-player/ft-shaka-video-player.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
translateSponsorBlockCategory
2525
} from '../../helpers/player/utils'
2626
import {
27-
addKeyboardShortcutToActionLabel,
27+
addKeyboardShortcutToActionTitle,
2828
getPicturesPath,
2929
showSaveDialog,
3030
showToast
@@ -1014,7 +1014,7 @@ export default defineComponent({
10141014
return
10151015
}
10161016

1017-
const localizationWithShortcut = addKeyboardShortcutToActionLabel(
1017+
const localizationWithShortcut = addKeyboardShortcutToActionTitle(
10181018
originalLocalization,
10191019
shortcut
10201020
)

src/renderer/components/ft-shaka-video-player/player-components/FullWindowButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import shaka from 'shaka-player'
22

33
import i18n from '../../../i18n/index'
44
import { KeyboardShortcuts } from '../../../../constants'
5-
import { addKeyboardShortcutToActionLabel } from '../../../helpers/utils'
5+
import { addKeyboardShortcutToActionTitle } from '../../../helpers/utils'
66

77
export class FullWindowButton extends shaka.ui.Element {
88
/**
@@ -78,7 +78,7 @@ export class FullWindowButton extends shaka.ui.Element {
7878

7979
const baseAriaLabel = this.fullWindowEnabled_ ? i18n.t('Video.Player.Exit Full Window') : i18n.t('Video.Player.Full Window')
8080

81-
this.button_.ariaLabel = addKeyboardShortcutToActionLabel(
81+
this.button_.ariaLabel = addKeyboardShortcutToActionTitle(
8282
baseAriaLabel,
8383
KeyboardShortcuts.VIDEO_PLAYER.FULLWINDOW
8484
)

src/renderer/components/ft-shaka-video-player/player-components/ScreenshotButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import shaka from 'shaka-player'
22

33
import i18n from '../../../i18n/index'
44
import { KeyboardShortcuts } from '../../../../constants'
5-
import { addKeyboardShortcutToActionLabel } from '../../../helpers/utils'
5+
import { addKeyboardShortcutToActionTitle } from '../../../helpers/utils'
66

77
export class ScreenshotButton extends shaka.ui.Element {
88
/**
@@ -51,7 +51,7 @@ export class ScreenshotButton extends shaka.ui.Element {
5151

5252
/** @private */
5353
updateLocalisedStrings_() {
54-
const label = addKeyboardShortcutToActionLabel(
54+
const label = addKeyboardShortcutToActionTitle(
5555
i18n.t('Video.Player.Take Screenshot'),
5656
KeyboardShortcuts.VIDEO_PLAYER.TAKE_SCREENSHOT
5757
)

src/renderer/components/ft-shaka-video-player/player-components/StatsButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import shaka from 'shaka-player'
22

33
import i18n from '../../../i18n/index'
44
import { KeyboardShortcuts } from '../../../../constants'
5-
import { addKeyboardShortcutToActionLabel } from '../../../helpers/utils'
5+
import { addKeyboardShortcutToActionTitle } from '../../../helpers/utils'
66

77
export class StatsButton extends shaka.ui.Element {
88
/**
@@ -70,7 +70,7 @@ export class StatsButton extends shaka.ui.Element {
7070
this.icon_.textContent = this.showStats_ ? 'insert_chart' : 'insert_chart_outlined'
7171

7272
const baseLabel = this.showStats_ ? i18n.t('Video.Player.Hide Stats') : i18n.t('Video.Player.Show Stats')
73-
const label = addKeyboardShortcutToActionLabel(
73+
const label = addKeyboardShortcutToActionTitle(
7474
baseLabel,
7575
KeyboardShortcuts.VIDEO_PLAYER.STATS
7676
)

src/renderer/components/ft-shaka-video-player/player-components/TheatreModeButton.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import shaka from 'shaka-player'
22

33
import i18n from '../../../i18n/index'
44
import { KeyboardShortcuts } from '../../../../constants'
5-
import { addKeyboardShortcutToActionLabel } from '../../../helpers/utils'
5+
import { addKeyboardShortcutToActionTitle } from '../../../helpers/utils'
66

77
export class TheatreModeButton extends shaka.ui.Element {
88
/**
@@ -77,7 +77,7 @@ export class TheatreModeButton extends shaka.ui.Element {
7777

7878
const baseAriaLabel = this.theatreModeEnabled_ ? i18n.t('Video.Player.Exit Theatre Mode') : i18n.t('Video.Player.Theatre Mode')
7979

80-
this.button_.ariaLabel = addKeyboardShortcutToActionLabel(
80+
this.button_.ariaLabel = addKeyboardShortcutToActionTitle(
8181
baseAriaLabel,
8282
KeyboardShortcuts.VIDEO_PLAYER.THEATRE_MODE
8383
)

src/renderer/components/side-nav/side-nav.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { defineComponent } from 'vue'
22
import FtFlexBox from '../ft-flex-box/ft-flex-box.vue'
33
import SideNavMoreOptions from '../side-nav-more-options/side-nav-more-options.vue'
44
import { youtubeImageUrlToInvidious } from '../../helpers/api/invidious'
5-
import { deepCopy } from '../../helpers/utils'
5+
import { deepCopy, localizeAndAddKeyboardShortcutToActionTitle } from '../../helpers/utils'
6+
import { KeyboardShortcuts } from '../../../constants'
67

78
export default defineComponent({
89
name: 'SideNav',
@@ -80,6 +81,22 @@ export default defineComponent({
8081
return {
8182
hiddenLabels: this.hideText
8283
}
84+
},
85+
historyTitle: function() {
86+
const shortcut = process.platform === 'darwin'
87+
? KeyboardShortcuts.APP.NAVIGATE_TO_HISTORY_MAC
88+
: KeyboardShortcuts.APP.NAVIGATE_TO_HISTORY
89+
90+
return localizeAndAddKeyboardShortcutToActionTitle(
91+
this.$t('History.History'),
92+
shortcut
93+
)
94+
},
95+
settingsTitle: function() {
96+
return localizeAndAddKeyboardShortcutToActionTitle(
97+
this.$t('Settings.Settings'),
98+
KeyboardShortcuts.APP.NAVIGATE_TO_SETTINGS
99+
)
83100
}
84101
}
85102
})

src/renderer/components/side-nav/side-nav.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@
132132
class="navOption mobileShow"
133133
role="button"
134134
to="/history"
135-
:title="$t('History.History')"
135+
:title="historyTitle"
136136
>
137137
<div
138138
class="thumbnailContainer"
@@ -156,7 +156,7 @@
156156
class="navOption mobileShow"
157157
role="button"
158158
to="/settings"
159-
:title="$t('Settings.Settings')"
159+
:title="settingsTitle"
160160
>
161161
<div
162162
class="thumbnailContainer"

src/renderer/components/top-nav/top-nav.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import FtProfileSelector from '../ft-profile-selector/ft-profile-selector.vue'
55
import debounce from 'lodash.debounce'
66

77
import { IpcChannels, KeyboardShortcuts, MOBILE_WIDTH_THRESHOLD } from '../../../constants'
8-
import { localizeAndAddKeyboardShortcutToActionLabel, openInternalPath } from '../../helpers/utils'
8+
import { localizeAndAddKeyboardShortcutToActionTitle, openInternalPath } from '../../helpers/utils'
99
import { translateWindowTitle } from '../../helpers/strings'
1010
import { clearLocalSearchSuggestionsSession, getLocalSearchSuggestions } from '../../helpers/api/local'
1111
import { invidiousAPICall } from '../../helpers/api/invidious'
@@ -87,21 +87,21 @@ export default defineComponent({
8787
},
8888

8989
forwardText: function () {
90-
return localizeAndAddKeyboardShortcutToActionLabel(
90+
return localizeAndAddKeyboardShortcutToActionTitle(
9191
this.$t('Forward'),
9292
KeyboardShortcuts.APP.HISTORY_FORWARD
9393
)
9494
},
9595

9696
backwardText: function () {
97-
return localizeAndAddKeyboardShortcutToActionLabel(
97+
return localizeAndAddKeyboardShortcutToActionTitle(
9898
this.$t('Back'),
9999
KeyboardShortcuts.APP.HISTORY_BACKWARD
100100
)
101101
},
102102

103103
newWindowText: function () {
104-
return localizeAndAddKeyboardShortcutToActionLabel(
104+
return localizeAndAddKeyboardShortcutToActionTitle(
105105
this.$t('Open New Window'),
106106
KeyboardShortcuts.APP.NEW_WINDOW
107107
)

src/renderer/helpers/utils.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -894,10 +894,11 @@ function getIndividualLocalizedShortcut(shortcut) {
894894
switch (shortcut) {
895895
case 'alt':
896896
return i18n.t('Keys.alt')
897+
case 'cmd':
897898
case 'ctrl':
898899
return process.platform === 'darwin'
899-
? i18n.t('Keys.ctrl')
900-
: i18n.t('Keys.cmd')
900+
? i18n.t('Keys.cmd')
901+
: i18n.t('Keys.ctrl')
901902
case 'arrowleft':
902903
return i18n.t('Keys.arrowleft')
903904
case 'arrowright':
@@ -911,6 +912,10 @@ function getIndividualLocalizedShortcut(shortcut) {
911912
}
912913
}
913914

915+
/**
916+
* @param {string} shortcut
917+
* @returns {string} the localized and recombined shortcut
918+
*/
914919
function getLocalizedShortcut(shortcut) {
915920
const shortcuts = shortcut.split('+')
916921
const localizedShortcuts = shortcuts.map((shortcut) => getIndividualLocalizedShortcut(shortcut))
@@ -919,14 +924,24 @@ function getLocalizedShortcut(shortcut) {
919924
return localizedShortcuts.join(shortcutJoinOperator)
920925
}
921926

922-
export function addKeyboardShortcutToActionLabel(actionLabel, shortcut) {
927+
/**
928+
* @param {string} actionTitle
929+
* @param {string} shortcut
930+
* @returns {string} the localized action title with keyboard shortcut
931+
*/
932+
export function addKeyboardShortcutToActionTitle(actionTitle, shortcut) {
923933
return i18n.t('KeyboardShortcutTemplate', {
924-
label: actionLabel,
934+
label: actionTitle,
925935
shortcut
926936
})
927937
}
928938

929-
export function localizeAndAddKeyboardShortcutToActionLabel(localizedActionLabel, unlocalizedShortcut) {
939+
/**
940+
* @param {string} localizedActionTitle
941+
* @param {string} unlocalizedShortcut
942+
* @returns {string} the localized action title with keyboard shortcut
943+
*/
944+
export function localizeAndAddKeyboardShortcutToActionTitle(localizedActionTitle, unlocalizedShortcut) {
930945
const localizedShortcut = getLocalizedShortcut(unlocalizedShortcut)
931-
return addKeyboardShortcutToActionLabel(localizedActionLabel, localizedShortcut)
946+
return addKeyboardShortcutToActionTitle(localizedActionTitle, localizedShortcut)
932947
}

0 commit comments

Comments
 (0)