2025-01-19 01:13:59 +08:00
|
|
|
class ApplicationController < ActionController::Base
|
2025-01-23 19:02:52 +08:00
|
|
|
include SeoConcern
|
2025-01-19 01:13:59 +08:00
|
|
|
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
2025-01-27 06:53:01 +08:00
|
|
|
# allow_browser versions: :modern
|
2025-01-27 07:40:13 +08:00
|
|
|
allow_browser do |config|
|
|
|
|
# 保留现代浏览器支持
|
|
|
|
config.use :modern
|
|
|
|
|
|
|
|
# 通用移动浏览器
|
|
|
|
config.allow(/Mobile Safari/) # iOS Safari
|
|
|
|
config.allow(/Chrome\/[\d.]+/) # Chrome 内核浏览器
|
|
|
|
|
|
|
|
# 国内主流浏览器
|
|
|
|
config.allow(/Quark\/[\d.]+/) # 夸克浏览器
|
|
|
|
config.allow(/HuaweiBrowser\/[\d.]+/) # 华为浏览器
|
|
|
|
config.allow(/MiuiBrowser\/[\d.]+/) # 小米浏览器
|
|
|
|
config.allow(/VivoBrowser\/[\d.]+/) # vivo浏览器
|
|
|
|
config.allow(/OppoBrowser\/[\d.]+/) # OPPO浏览器
|
|
|
|
config.allow(/UCBrowser\/[\d.]+/) # UC浏览器
|
|
|
|
config.allow(/QQBrowser\/[\d.]+/) # QQ浏览器
|
|
|
|
config.allow(/MicroMessenger\/[\d.]+/) # 微信内置浏览器
|
|
|
|
config.allow(/Alipay/) # 支付宝内置浏览器
|
|
|
|
config.allow(/BaiduBoxApp/) # 百度 App
|
|
|
|
config.allow(/baiduboxapp/i) # 百度 App (小写)
|
|
|
|
config.allow(/SogouMobile/) # 搜狗移动浏览器
|
|
|
|
config.allow(/Weibo/) # 微博内置浏览器
|
|
|
|
config.allow(/DingTalk/) # 钉钉内置浏览器
|
|
|
|
config.allow(/ToutiaoMicroApp/) # 今日头条小程序
|
|
|
|
config.allow(/BytedanceWebview/) # 字节跳动系浏览器
|
|
|
|
config.allow(/ArkWeb/) # 鸿蒙浏览器
|
|
|
|
|
|
|
|
# 调试日志(开发环境)
|
|
|
|
if Rails.env.development?
|
|
|
|
config.on_failure do |browser|
|
|
|
|
Rails.logger.info <<~INFO
|
|
|
|
Browser blocked:
|
|
|
|
Name: #{browser.name}
|
|
|
|
Version: #{browser.version}
|
|
|
|
User Agent: #{browser.ua}
|
|
|
|
INFO
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2025-01-21 18:27:26 +08:00
|
|
|
before_action :set_locale
|
2025-01-27 00:43:18 +08:00
|
|
|
after_action :track_action
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def track_action
|
|
|
|
ahoy.track "Viewed Application", request.path_parameters
|
|
|
|
end
|
2025-01-21 18:27:26 +08:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_locale
|
|
|
|
I18n.locale = params[:locale] || I18n.default_locale
|
|
|
|
end
|
2025-01-19 01:13:59 +08:00
|
|
|
end
|