0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-04 10:39:43 +08:00
discourse/lib/mobile_detection.rb
David Taylor 9aa52af4c9
UX: Drop legacy mobile-mode site settings (#40226)
Viewport-based mobile mode has been the default since September, and the
feedback has been overwhelmingly positive. This is now the only
supported method.

`enable_mobile_theme` is an extremely old hidden setting, which doesn't
make sense at all now that almost all Discourse design is
viewport-based.

This commit cleans up both, and all their associated logic/tests. On the
server-side, we standardize any remaining mobile-user-agent logic to be
described as `mobile_device?` instead of `mobile_view?`, so that it has
parity with the client-side `capabilities` service.
2026-05-26 09:23:13 +01:00

27 lines
682 B
Ruby
Vendored

# frozen_string_literal: true
module MobileDetection
# if the criteria for mobile_device? changes, update the code for `isMobileDevice` in
# `frontend/discourse/app/services/capabilities.js`
def self.mobile_device?(user_agent)
user_agent =~ /Mobile/ && !(user_agent =~ /iPad/)
end
MODERN_MOBILE_REGEX =
%r{
\(.*iPhone\ OS\ 1[6-9].*\)|
\(.*iPad.*OS\ 1[6-9].*\)|
Chrome\/8[89]|
Chrome\/9[0-9]|
Chrome\/1[0-9][0-9]|
Firefox\/8[5-9]|
Firefox\/9[0-9]|
Firefox\/1[0-9][0-9]
}x
USER_AGENT_MAX_LENGTH = 400
def self.modern_mobile_device?(user_agent)
user_agent[0...USER_AGENT_MAX_LENGTH].match?(MODERN_MOBILE_REGEX)
end
end