mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
30990006a9
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
67 lines
1021 B
Ruby
67 lines
1021 B
Ruby
# frozen_string_literal: true
|
|
|
|
module BrowserDetection
|
|
|
|
def self.browser(user_agent)
|
|
case user_agent
|
|
when /Edge/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 /DiscourseHub/i
|
|
:discoursehub
|
|
else
|
|
:unknown
|
|
end
|
|
end
|
|
|
|
def self.device(user_agent)
|
|
case user_agent
|
|
when /Android/i
|
|
:android
|
|
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 /iPhone|iPad|iPod/i
|
|
:ios
|
|
when /Macintosh/i
|
|
:macos
|
|
when /Linux/i
|
|
:linux
|
|
when /Windows/i
|
|
:windows
|
|
else
|
|
:unknown
|
|
end
|
|
end
|
|
|
|
end
|