mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
refactor: only run detectOS once
This commit is contained in:
parent
b2daa4c3b5
commit
3d51bd6b84
2 changed files with 8 additions and 7 deletions
|
|
@ -3,7 +3,7 @@ import Icon from 'components/Icon'
|
|||
import cx from 'utils/cx'
|
||||
import LoadingIndicator from 'components/LoadingIndicator'
|
||||
import { TreeNode } from 'utils/VisibleNodesGenerator'
|
||||
import { detectOS, OperatingSystems } from 'utils/general'
|
||||
import { os, OperatingSystems } from 'utils/general'
|
||||
|
||||
function getIconType(node: TreeNode) {
|
||||
switch (node.type) {
|
||||
|
|
@ -27,8 +27,8 @@ type Props = {
|
|||
export default class Node extends React.PureComponent<Props> {
|
||||
onClick: React.MouseEventHandler = event => {
|
||||
if (
|
||||
(detectOS() === OperatingSystems.macOS && event.metaKey) ||
|
||||
(detectOS() === OperatingSystems.Windows && event.ctrlKey)
|
||||
(os === OperatingSystems.macOS && event.metaKey) ||
|
||||
(os === OperatingSystems.Windows && event.ctrlKey)
|
||||
) {
|
||||
// Open in new tab
|
||||
return
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export enum OperatingSystems {
|
|||
others = 'unknown',
|
||||
}
|
||||
|
||||
export function detectOS(): OperatingSystems {
|
||||
function detectOS(): OperatingSystems {
|
||||
const {
|
||||
navigator: { userAgent },
|
||||
} = window
|
||||
|
|
@ -30,12 +30,13 @@ export function detectOS(): OperatingSystems {
|
|||
return OperatingSystems.others
|
||||
}
|
||||
|
||||
export const os = detectOS()
|
||||
|
||||
export function friendlyFormatShortcut(shortcut?: string) {
|
||||
if (!shortcut) return ''
|
||||
const OS = detectOS()
|
||||
if (OS === OperatingSystems.Windows) {
|
||||
if (os === OperatingSystems.Windows) {
|
||||
return shortcut.replace(/meta/, 'win')
|
||||
} else if (OS === OperatingSystems.macOS) {
|
||||
} else if (os === OperatingSystems.macOS) {
|
||||
return shortcut
|
||||
.replace(/meta/, '⌘')
|
||||
.replace(/ctrl/, '⌃')
|
||||
|
|
|
|||
Loading…
Reference in a new issue