diff options
| author | Md Saban <45597394+mdsaban@users.noreply.github.com> | 2024-06-22 21:20:14 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-22 16:50:14 +0100 |
| commit | ccfff6b1954030a273b0612f3772ec00a82422c8 (patch) | |
| tree | 29b9c9ce9828ead27ff09aa5ac3b1e7698c87fd8 /apps/web/lib | |
| parent | 16f21bf9ee747a4fc8fd235eee5c0348d355aae2 (diff) | |
| download | karakeep-ccfff6b1954030a273b0612f3772ec00a82422c8.tar.zst | |
fix(web): Fix save action on empty card. Fixes #225 (#243)
* fix: Empty item save action
* fix: resolve comments
* chore: prettier
Diffstat (limited to 'apps/web/lib')
| -rw-r--r-- | apps/web/lib/utils.ts | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/apps/web/lib/utils.ts b/apps/web/lib/utils.ts index 88283f01..12207765 100644 --- a/apps/web/lib/utils.ts +++ b/apps/web/lib/utils.ts @@ -5,3 +5,27 @@ import { twMerge } from "tailwind-merge"; export function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } + +export type OS = "macos" | "ios" | "windows" | "android" | "linux" | null; + +export function getOS() { + if (typeof window === "undefined") return; + const userAgent = window.navigator.userAgent.toLowerCase(); + const macosPlatforms = /(macintosh|macintel|macppc|mac68k|macos)/i; + const windowsPlatforms = /(win32|win64|windows|wince)/i; + const iosPlatforms = /(iphone|ipad|ipod)/i; + let os: OS = null; + + if (macosPlatforms.test(userAgent)) { + os = "macos"; + } else if (iosPlatforms.test(userAgent)) { + os = "ios"; + } else if (windowsPlatforms.test(userAgent)) { + os = "windows"; + } else if (/android/.test(userAgent)) { + os = "android"; + } else if (!os && /linux/.test(userAgent)) { + os = "linux"; + } + return os; +} |
