mirror of
https://github.com/discourse/discourse.git
synced 2026-08-04 10:39:43 +08:00
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.
27 lines
682 B
Ruby
Vendored
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
|