Skip to content

Commit

Permalink
Use Mac icons in keyboard shortcuts for Macs
Browse files Browse the repository at this point in the history
  • Loading branch information
kommunarr committed Oct 20, 2024
1 parent 16693ea commit cf263fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
42 changes: 31 additions & 11 deletions src/renderer/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,16 +892,10 @@ export function getChannelPlaylistId(channelId, type, sortBy) {

function getIndividualLocalizedShortcut(shortcut) {
switch (shortcut) {
case 'option':
case 'alt':
return process.platform === 'darwin'
? i18n.t('Keys.option')
: i18n.t('Keys.alt')
case 'cmd':
return i18n.t('Keys.alt')
case 'ctrl':
return process.platform === 'darwin'
? i18n.t('Keys.cmd')
: i18n.t('Keys.ctrl')
return i18n.t('Keys.ctrl')
case 'arrowleft':
return i18n.t('Keys.arrowleft')
case 'arrowright':
Expand All @@ -915,16 +909,42 @@ function getIndividualLocalizedShortcut(shortcut) {
}
}

function getMacIconForShortcut(shortcut) {
switch (shortcut) {
case 'option':
case 'alt':
return '⌥'
case 'cmd':
case 'ctrl':
return '⌘'
case 'arrowleft':
return '◀'
case 'arrowright':
return '▶'
case 'arrowup':
return '▲'
case 'arrowdown':
return '▼'
default:
return shortcut
}
}

/**
* @param {string} shortcut
* @returns {string} the localized and recombined shortcut
*/
function getLocalizedShortcut(shortcut) {
const shortcuts = shortcut.split('+')
const localizedShortcuts = shortcuts.map((shortcut) => getIndividualLocalizedShortcut(shortcut))

const shortcutJoinOperator = i18n.t('shortcutJoinOperator')
return localizedShortcuts.join(shortcutJoinOperator)
if (process.platform === 'darwin') {
const shortcutsAsIcons = shortcuts.map((shortCut => getMacIconForShortcut(shortCut)))
return shortcutsAsIcons.join('')
} else {
const localizedShortcuts = shortcuts.map((shortcut) => getIndividualLocalizedShortcut(shortcut))
const shortcutJoinOperator = i18n.t('shortcutJoinOperator')
return localizedShortcuts.join(shortcutJoinOperator)
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions static/locales/en-US.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1134,9 +1134,7 @@ KeyboardShortcutTemplate: '{label} ({shortcut})'
shortcutJoinOperator: +
Keys:
alt: Alt
cmd: Cmd
ctrl: Ctrl
option: Option
arrowdown: Down Arrow
arrowleft: Left Arrow
arrowright: Right Arrow
Expand Down

0 comments on commit cf263fb

Please sign in to comment.