Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions apps/site/util/detectOS.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
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';
}
// Match OS names and convert to uppercase directly if there's a match
const osMatch = userAgent?.match(/(Win|Mac|Linux|AIX)/);
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);