-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from devtobi/63-add-functionality-to-detect-op…
…erating-system feat: added feature to detect operating system and show custom icon
- Loading branch information
Showing
7 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
/// <reference types="vite/client" /> | ||
/// <reference types="user-agent-data-types" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { | ||
iosPlatforms, | ||
macOSPlatforms, | ||
OperatingSystem, | ||
windowsPlatforms, | ||
} from '@/types/OperatingSystem'; | ||
|
||
export const getOperatingSystem = () => { | ||
const userAgent = window.navigator.userAgent; | ||
const platform = | ||
window.navigator?.userAgentData?.platform || window.navigator.platform; | ||
|
||
switch (true) { | ||
case macOSPlatforms.includes(platform): | ||
return OperatingSystem.MACOS; | ||
case iosPlatforms.includes(platform): | ||
return OperatingSystem.IOS; | ||
case windowsPlatforms.includes(platform): | ||
return OperatingSystem.WINDOWS; | ||
case /Android/.test(userAgent): | ||
return OperatingSystem.ANDROID; | ||
case /Linux/.test(platform): | ||
return OperatingSystem.LINUX; | ||
default: | ||
return OperatingSystem.OTHER; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { PrimeIcons } from 'primevue/api'; | ||
|
||
import { getOperatingSystem } from '@/helpers/getOperatingSystem'; | ||
import { OperatingSystem } from '@/types/OperatingSystem'; | ||
|
||
export const getOperatingSystemIcon = () => { | ||
const os = getOperatingSystem(); | ||
|
||
const iconMap: Record<OperatingSystem, string> = { | ||
[OperatingSystem.MACOS]: PrimeIcons.APPLE, | ||
[OperatingSystem.WINDOWS]: PrimeIcons.MICROSOFT, | ||
[OperatingSystem.LINUX]: PrimeIcons.DESKTOP, | ||
[OperatingSystem.IOS]: PrimeIcons.APPLE, | ||
[OperatingSystem.ANDROID]: PrimeIcons.ANDROID, | ||
[OperatingSystem.OTHER]: PrimeIcons.DESKTOP, | ||
}; | ||
|
||
return iconMap[os]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export enum OperatingSystem { | ||
MACOS, | ||
WINDOWS, | ||
LINUX, | ||
IOS, | ||
ANDROID, | ||
OTHER, | ||
} | ||
|
||
export const macOSPlatforms = [ | ||
'macOS', | ||
'Macintosh', | ||
'MacIntel', | ||
'MacPPC', | ||
'Mac68K', | ||
]; | ||
export const windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE']; | ||
export const iosPlatforms = ['iPhone', 'iPad', 'iPod']; |