mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 08:33:39 +08:00
8aa5df69f0
It used to show up as an unknown device and browser in user preferences (Recently Used Devices).
71 lines
1.1 KiB
Ruby
71 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module BrowserDetection
|
|
|
|
def self.browser(user_agent)
|
|
case user_agent
|
|
when /Edg/i
|
|
:edge
|
|
when /Opera/i, /OPR/i
|
|
:opera
|
|
when /Firefox/i
|
|
:firefox
|
|
when /Chrome/i, /CriOS/i
|
|
:chrome
|
|
when /Safari/i
|
|
:safari
|
|
when /MSIE/i, /Trident/i
|
|
:ie
|
|
when /Discourse/i
|
|
:discoursehub
|
|
else
|
|
:unknown
|
|
end
|
|
end
|
|
|
|
def self.device(user_agent)
|
|
case user_agent
|
|
when /Android/i
|
|
:android
|
|
when /CrOS/i
|
|
:chromebook
|
|
when /iPad/i
|
|
:ipad
|
|
when /iPhone/i
|
|
:iphone
|
|
when /iPod/i
|
|
:ipod
|
|
when /Mobile/i
|
|
:mobile
|
|
when /Macintosh/i
|
|
:mac
|
|
when /Linux/i
|
|
:linux
|
|
when /Windows/i
|
|
:windows
|
|
else
|
|
:unknown
|
|
end
|
|
end
|
|
|
|
def self.os(user_agent)
|
|
case user_agent
|
|
when /Android/i
|
|
:android
|
|
when /CrOS/i
|
|
:chromeos
|
|
when /iPhone|iPad|iPod|Darwin/i
|
|
:ios
|
|
when /Macintosh/i
|
|
:macos
|
|
when /Linux/i
|
|
:linux
|
|
when /Windows/i
|
|
:windows
|
|
else
|
|
:unknown
|
|
end
|
|
end
|
|
|
|
end
|