diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-07-24 01:00:42 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-07-24 01:00:42 -0700 |
commit | 2e376b7e61f68a48ccb2a5be7ab6ab55ab30c670 (patch) | |
tree | 6c1077859938fadce3a6f17f267127a66fd11df4 /extension/react-app/src/util/index.ts | |
parent | 59c549a468abd40207f8dc46eacdc0e02bbe21ad (diff) | |
parent | 82b03aeb0882cb884c398104b7934d63c6ceed00 (diff) | |
download | sncontinue-2e376b7e61f68a48ccb2a5be7ab6ab55ab30c670.tar.gz sncontinue-2e376b7e61f68a48ccb2a5be7ab6ab55ab30c670.tar.bz2 sncontinue-2e376b7e61f68a48ccb2a5be7ab6ab55ab30c670.zip |
Merge branch 'main' into show-react-immediately
Diffstat (limited to 'extension/react-app/src/util/index.ts')
-rw-r--r-- | extension/react-app/src/util/index.ts | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/extension/react-app/src/util/index.ts b/extension/react-app/src/util/index.ts new file mode 100644 index 00000000..c4168e13 --- /dev/null +++ b/extension/react-app/src/util/index.ts @@ -0,0 +1,43 @@ +type Platform = "mac" | "linux" | "windows" | "unknown"; + +export function getPlatform(): Platform { + const platform = window.navigator.platform.toUpperCase(); + if (platform.indexOf("MAC") >= 0) { + return "mac"; + } else if (platform.indexOf("LINUX") >= 0) { + return "linux"; + } else if (platform.indexOf("WIN") >= 0) { + return "windows"; + } else { + return "unknown"; + } +} + +export function isMetaEquivalentKeyPressed(event: { + metaKey: boolean; + ctrlKey: boolean; +}): boolean { + const platform = getPlatform(); + switch (platform) { + case "mac": + return event.metaKey; + case "linux": + case "windows": + return event.ctrlKey; + default: + return event.metaKey; + } +} + +export function getMetaKeyLabel(): string { + const platform = getPlatform(); + switch (platform) { + case "mac": + return "⌘"; + case "linux": + case "windows": + return "^"; + default: + return "⌘"; + } +} |