This repository has been archived by the owner on Apr 29, 2023. It is now read-only.
/
useragent.cljs
78 lines (62 loc) · 1.95 KB
/
useragent.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
(ns oc.lib.cljs.useragent
(:require [goog.userAgent :as ua]
[goog.userAgent.platform :as plat]
[goog.userAgent.product :as prod]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; OS Detection
(def mac? ua/MAC)
(def windows? ua/WINDOWS)
(def linux? ua/LINUX)
(def android? ua/ANDROID)
(def ios? ua/IOS)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Browser detection
(def edge? ua/EDGE)
(def ie-or-edge? ua/EDGE_OR_IE)
(def gecko? ua/GECKO)
(def ie? ua/IE)
(def opera? ua/OPERA)
(def chrome? prod/CHROME)
(def safari? prod/SAFARI)
(def firefox? prod/FIREFOX)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Platform detection
(def ipad? ua/IPAD)
(def iphone? ua/IPHONE)
(def ipod? ua/IPOD)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; General detection
(def mobile? ua/MOBILE)
(def webkit? ua/WEBKIT)
(def x11? ua/X11)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Version awareness
(def ^{:doc "The string that describes the version number of the user agent."}
browser-version
ua/VERSION)
(def ^{:doc "
Detects the version of the OS/platform the browser is running in.
Not supported for Linux, where an empty string is returned."}
os-version
plat/VERSION)
(defn browser-version-or-higher?
"Returns true if the browser version is v or higher."
[v]
(ua/isVersionOrHigher v))
(defn os-version-or-higher?
"Returns true if the OS/platform is v or higher."
[v]
(plat/isVersion v))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Carrot-specific detection
(def ^{:doc "Whether we're running in the desktop application"}
desktop-app?
;; injected by the Electron shell
(some? js/window.OCCarrotDesktop))
(def ^{:doc "Whether we're running in the mobile application"}
mobile-app?
;; injected by the Expo shell
(some? js/window.ReactNativeWebView))
(def ^{:doc "Whether we're running in a web-in-native wrapper (e.g. electron, expo, etc)"}
pseudo-native?
(or desktop-app? mobile-app?))