Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[@mantine/core]: add ChromeOS to useOS #6541

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions packages/@mantine/hooks/src/use-os/use-os.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const platforms = {
android: [
'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Mobile Safari/537.36',
],
chromeos: [
'Mozilla/5.0 (X11; CrOS x86_64 13310.93.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.133 Safari/537.36',
],
undetermined: ['UNKNOWN'],
} as const;

Expand Down
10 changes: 9 additions & 1 deletion packages/@mantine/hooks/src/use-os/use-os.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useState } from 'react';
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';

export type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux';
export type OS = 'undetermined' | 'macos' | 'ios' | 'windows' | 'android' | 'linux' | 'chromeos';

function isMacOS(userAgent: string): boolean {
const macosPattern = /(Macintosh)|(MacIntel)|(MacPPC)|(Mac68K)/i;
Expand Down Expand Up @@ -33,6 +33,11 @@ function isLinux(userAgent: string): boolean {
return linuxPattern.test(userAgent);
}

function isChromeOS(userAgent: string): boolean {
const chromePattern = /CrOS/i;
return chromePattern.test(userAgent);
}

function getOS(): OS {
if (typeof window === 'undefined') {
return 'undetermined';
Expand All @@ -55,6 +60,9 @@ function getOS(): OS {
if (isLinux(userAgent)) {
return 'linux';
}
if (isChromeOS(userAgent)) {
return 'chromeos';
}

return 'undetermined';
}
Expand Down
Loading