From ae2cfdd44e9ce5efb514ddcc5923cac1e76856e1 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 4 Mar 2020 16:23:54 +0100 Subject: [PATCH] Update browser gem `modern?` method was removed in version 4 --- Gemfile.lock | 2 +- app/controllers/application_controller.rb | 2 +- app/helpers/application_helper.rb | 8 ++++++++ app/services/browser_support.rb | 13 +++++++++++++ .../layouts/_outdated_browser_banner.html.haml | 3 +-- config/initializers/browser.rb | 8 -------- 6 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 app/services/browser_support.rb delete mode 100644 config/initializers/browser.rb diff --git a/Gemfile.lock b/Gemfile.lock index b4e63f9ef..6265df9f2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -118,7 +118,7 @@ GEM bootstrap-wysihtml5-rails (0.3.3.8) railties (>= 3.0) brakeman (4.3.1) - browser (2.5.3) + browser (4.0.0) builder (3.2.4) byebug (10.0.2) capybara (3.29.0) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index c192c0f75..b78fe1b90 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -233,7 +233,7 @@ class ApplicationController < ActionController::Base key: sentry[:client_key], enabled: sentry[:enabled], environment: sentry[:environment], - browser: { modern: browser.modern? }, + browser: { modern: BrowserSupport.supported?(browser) }, user: sentry_user } end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 9929ab7f6..e45d95781 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -131,4 +131,12 @@ module ApplicationHelper def has_dismissed_outdated_browser_banner? cookies[:dismissed_outdated_browser_banner] == 'true' end + + def supported_browser? + BrowserSupport.supported?(browser) + end + + def show_outdated_browser_banner? + !supported_browser? && !has_dismissed_outdated_browser_banner? + end end diff --git a/app/services/browser_support.rb b/app/services/browser_support.rb new file mode 100644 index 000000000..46f5a372d --- /dev/null +++ b/app/services/browser_support.rb @@ -0,0 +1,13 @@ +class BrowserSupport + def self.supported?(browser) + # See .browserslistrc + [ + browser.chrome? && browser.version.to_i >= 50 && !browser.platform.ios?, + browser.edge? && browser.version.to_i >= 14 && !browser.compatibility_view?, + browser.firefox? && browser.version.to_i >= 50 && !browser.platform.ios?, + browser.opera? && browser.version.to_i >= 40, + browser.safari? && browser.version.to_i >= 8, + browser.platform.ios? && browser.platform.version.to_i >= 8 + ].any? + end +end diff --git a/app/views/layouts/_outdated_browser_banner.html.haml b/app/views/layouts/_outdated_browser_banner.html.haml index ee39e191d..25a8bcbd8 100644 --- a/app/views/layouts/_outdated_browser_banner.html.haml +++ b/app/views/layouts/_outdated_browser_banner.html.haml @@ -1,5 +1,4 @@ --# See config/browser.rb -- if !browser.modern? && !has_dismissed_outdated_browser_banner? +- if show_outdated_browser_banner? #outdated-browser-banner.site-banner .container .site-banner-icon ⚠️ diff --git a/config/initializers/browser.rb b/config/initializers/browser.rb deleted file mode 100644 index f9d22d40b..000000000 --- a/config/initializers/browser.rb +++ /dev/null @@ -1,8 +0,0 @@ -# See .browserslistrc -Browser.modern_rules.clear -Browser.modern_rules << -> b { b.chrome? && b.version.to_i >= 50 && !b.platform.ios? } -Browser.modern_rules << -> b { b.edge? && b.version.to_i >= 14 && !b.compatibility_view? } -Browser.modern_rules << -> b { b.firefox? && b.version.to_i >= 50 && !b.platform.ios? } -Browser.modern_rules << -> b { b.opera? && b.version.to_i >= 40 } -Browser.modern_rules << -> b { b.safari? && b.version.to_i >= 8 } -Browser.modern_rules << -> b { b.platform.ios? && b.platform.version.to_i >= 8 }