From 93eaf71e220f5f8fa6be7f6d725ccfda1cd32bad Mon Sep 17 00:00:00 2001 From: CodingRule Date: Tue, 19 Nov 2024 04:30:20 -0800 Subject: [PATCH 1/4] Update detectOS.ts Signed-off-by: CodingRule --- apps/site/util/detectOS.ts | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/apps/site/util/detectOS.ts b/apps/site/util/detectOS.ts index 92b8f2277e39e..1e1462a73882c 100644 --- a/apps/site/util/detectOS.ts +++ b/apps/site/util/detectOS.ts @@ -1,21 +1,16 @@ import type { UserOS } from '@/types/userOS'; export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => { - const osMatch = userAgent?.match(/(Win|Mac|Linux)/); - switch (osMatch && osMatch[1]) { - case 'Win': - return 'WIN'; - case 'Mac': - return 'MAC'; - case 'Linux': - return 'LINUX'; - case 'AIX': - return 'AIX'; - default: - return 'OTHER'; - } + const osMatch = userAgent?.match(/(Win|Mac|Linux|AIX)/); + const osMap: Record = { + Win: 'WIN', + Mac: 'MAC', + Linux: 'LINUX', + AIX: 'AIX', + }; + return osMap[osMatch?.[1] ?? ''] || 'OTHER'; }; -// Since `navigator.appVersion` is deprecated, we use the `userAgent`` +// Since navigator.appVersion is deprecated, we use the userAgent // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent); From 0eb25b7b93ca6c2d72d9978e43abcb93fa2a7a38 Mon Sep 17 00:00:00 2001 From: CodingRule Date: Tue, 19 Nov 2024 05:11:14 -0800 Subject: [PATCH 2/4] Update detectOS.ts Signed-off-by: CodingRule --- apps/site/util/detectOS.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/site/util/detectOS.ts b/apps/site/util/detectOS.ts index 1e1462a73882c..9c61f65b865ee 100644 --- a/apps/site/util/detectOS.ts +++ b/apps/site/util/detectOS.ts @@ -11,6 +11,6 @@ export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => { return osMap[osMatch?.[1] ?? ''] || 'OTHER'; }; -// Since navigator.appVersion is deprecated, we use the userAgent +// Since `navigator.appVersion` is deprecated, we use the `userAgent`` // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent); From f3dd6998552c1014e6747fc55570f7f350f232c6 Mon Sep 17 00:00:00 2001 From: CodingRule Date: Tue, 19 Nov 2024 15:58:38 +0200 Subject: [PATCH 3/4] Update detectOS.ts Signed-off-by: CodingRule --- apps/site/util/detectOS.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/site/util/detectOS.ts b/apps/site/util/detectOS.ts index 9c61f65b865ee..a7ce89b561a1d 100644 --- a/apps/site/util/detectOS.ts +++ b/apps/site/util/detectOS.ts @@ -1,16 +1,12 @@ import type { UserOS } from '@/types/userOS'; export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => { + // Match OS names and convert to uppercase directly if there's a match const osMatch = userAgent?.match(/(Win|Mac|Linux|AIX)/); - const osMap: Record = { - Win: 'WIN', - Mac: 'MAC', - Linux: 'LINUX', - AIX: 'AIX', - }; - return osMap[osMatch?.[1] ?? ''] || 'OTHER'; + return osMatch ? (osMatch[1].toUpperCase() as UserOS) : 'OTHER'; }; + // Since `navigator.appVersion` is deprecated, we use the `userAgent`` // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent); From aae02eb8dca58db770ba9aff5daec1b3ddc259e3 Mon Sep 17 00:00:00 2001 From: CodingRule Date: Tue, 19 Nov 2024 16:06:55 +0200 Subject: [PATCH 4/4] Update apps/site/util/detectOS.ts Co-authored-by: Aviv Keller Signed-off-by: CodingRule --- apps/site/util/detectOS.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/site/util/detectOS.ts b/apps/site/util/detectOS.ts index a7ce89b561a1d..351eb1a9fe444 100644 --- a/apps/site/util/detectOS.ts +++ b/apps/site/util/detectOS.ts @@ -6,7 +6,6 @@ export const detectOsInUserAgent = (userAgent: string | undefined): UserOS => { return osMatch ? (osMatch[1].toUpperCase() as UserOS) : 'OTHER'; }; - // Since `navigator.appVersion` is deprecated, we use the `userAgent`` // https://developer.mozilla.org/en-US/docs/Web/API/Navigator/appVersion export const detectOS = (): UserOS => detectOsInUserAgent(navigator?.userAgent);