Skip to content

Instantly share code, notes, and snippets.

@AvocadoVenom
Last active July 8, 2022 07:26
Show Gist options
  • Save AvocadoVenom/d6abe36ef32c6cf2bc4f30316479bec7 to your computer and use it in GitHub Desktop.
Save AvocadoVenom/d6abe36ef32c6cf2bc4f30316479bec7 to your computer and use it in GitHub Desktop.
enum DesktopOS {
Linux = 'linux',
MacOS = 'mac_os',
Unix = 'unix',
Unknown = 'unknown',
Windows = 'windows'
}
const getDesktopOS = (): DesktopOS | undefined => {
if (isDesktopDevice()) {
if (userAgent.indexOf('Win') !== -1) return DesktopOS.Windows
else if (userAgent.indexOf('Mac') !== -1) return DesktopOS.MacOS
else if (userAgent.indexOf('X11') !== -1) return DesktopOS.Unix
else if (userAgent.indexOf('Linux') !== -1) return DesktopOS.Linux
return DesktopOS.Unknown
} else return undefined
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment