From ccfff6b1954030a273b0612f3772ec00a82422c8 Mon Sep 17 00:00:00 2001 From: Md Saban <45597394+mdsaban@users.noreply.github.com> Date: Sat, 22 Jun 2024 21:20:14 +0530 Subject: fix(web): Fix save action on empty card. Fixes #225 (#243) * fix: Empty item save action * fix: resolve comments * chore: prettier --- apps/web/lib/utils.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'apps/web/lib/utils.ts') 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; +} -- cgit v1.2.3-70-g09d2