diff --git a/src/components/SettingsBar.tsx b/src/components/SettingsBar.tsx index 0705791..4670c7c 100644 --- a/src/components/SettingsBar.tsx +++ b/src/components/SettingsBar.tsx @@ -2,6 +2,7 @@ import * as React from 'react' import Icon from 'components/Icon' import configHelper, { config } from 'utils/configHelper' import keyHelper from 'utils/keyHelper' +import { friendlyFormatShortcut } from 'utils/general.js' import { version } from '../../package.json' const wikiLinks = { @@ -13,38 +14,6 @@ const wikiLinks = { const ACCESS_TOKEN_REGEXP = /^[0-9a-f]{40}$/ -const OperatingSystems = { - Windows: 'Windows', - macOS: 'Macintosh', - others: 'unknown', -} - -function detectOS() { - const { - navigator: { userAgent }, - } = window - if (userAgent.indexOf(OperatingSystems.Windows) !== -1) return OperatingSystems.Windows - else if (userAgent.indexOf(OperatingSystems.macOS) !== -1) return OperatingSystems.macOS - return OperatingSystems.others -} - -function friendlyFormatShortcut(shortcut?: string) { - if (!shortcut) return '' - const OS = detectOS() - if (OS === OperatingSystems.Windows) { - return shortcut.replace(/meta/, 'win') - } else if (OS === OperatingSystems.macOS) { - return shortcut - .replace(/meta/, '⌘') - .replace(/ctrl/, '⌃') - .replace(/shift/, '⇧') - .replace(/alt/, '⌥') - .toUpperCase() - } else { - return shortcut - } -} - type Props = { accessToken?: string activated: boolean diff --git a/src/utils/general.ts b/src/utils/general.ts index 34dee8b..522f544 100644 --- a/src/utils/general.ts +++ b/src/utils/general.ts @@ -12,3 +12,35 @@ export function pick(source: T, keys: string[]): Partial { } return {} as Partial } + +const OperatingSystems = { + Windows: 'Windows', + macOS: 'Macintosh', + others: 'unknown', +} + +function detectOS() { + const { + navigator: { userAgent }, + } = window + if (userAgent.indexOf(OperatingSystems.Windows) !== -1) return OperatingSystems.Windows + else if (userAgent.indexOf(OperatingSystems.macOS) !== -1) return OperatingSystems.macOS + return OperatingSystems.others +} + +export function friendlyFormatShortcut(shortcut?: string) { + if (!shortcut) return '' + const OS = detectOS() + if (OS === OperatingSystems.Windows) { + return shortcut.replace(/meta/, 'win') + } else if (OS === OperatingSystems.macOS) { + return shortcut + .replace(/meta/, '⌘') + .replace(/ctrl/, '⌃') + .replace(/shift/, '⇧') + .replace(/alt/, '⌥') + .toUpperCase() + } else { + return shortcut + } +}