diff --git a/lib/browser/base.rb b/lib/browser/base.rb index 157689b5..1fe0d997 100644 --- a/lib/browser/base.rb +++ b/lib/browser/base.rb @@ -214,6 +214,18 @@ def huawei_browser?(expected_version = nil) detect_version?(full_version, expected_version) end + # 钉钉浏览器 + def ding_talk_browser?(expected_version = nil) + instance_of?(DingTalkBrowser) && + detect_version?(full_version, expected_version) + end + + # 企业微信浏览器 + def wework_browser?(expected_version = nil) + instance_of?(WeworkBrowser) && + detect_version?(full_version, expected_version) + end + # Detect if browser is Xiaomi Miui. def miui_browser?(expected_version = nil) instance_of?(MiuiBrowser) && diff --git a/lib/browser/browser.rb b/lib/browser/browser.rb index adb84274..0a81edf9 100644 --- a/lib/browser/browser.rb +++ b/lib/browser/browser.rb @@ -34,6 +34,8 @@ require_relative "samsung_browser" require_relative "huawei_browser" require_relative "miui_browser" +require_relative "wework_browser" +require_relative "ding_talk_browser" require_relative "maxthon" require_relative "sougou_browser" require_relative "google_search_app" @@ -82,6 +84,8 @@ def self.matchers Snapchat, # must be placed before Chrome and Safari Weibo, # must be placed before Chrome and Safari MicroMessenger, # must be placed before QQ + WeworkBrowser, + DingTalkBrowser, QQ, # must be placed before Chrome and Safari Alipay, # must be placed before Chrome and Safari Electron, # must be placed before Chrome and Safari diff --git a/lib/browser/chrome.rb b/lib/browser/chrome.rb index 4b8410f3..f7fde9a4 100644 --- a/lib/browser/chrome.rb +++ b/lib/browser/chrome.rb @@ -33,6 +33,8 @@ def match? !sputnik? && !samsung_browser? && !huawei_browser? && + !wework_browser? && + !ding_talk_browser? && !miui_browser? && !maxthon? && !qq? && diff --git a/lib/browser/ding_talk_browser.rb b/lib/browser/ding_talk_browser.rb new file mode 100644 index 00000000..0ac87bf6 --- /dev/null +++ b/lib/browser/ding_talk_browser.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Browser + class DingTalkBrowser < Base + def id + :ding_talk_browser + end + + def name + "DingTalkBrowser" + end + + def full_version + ua[%r{DingTalk/([\d.]+)}, 1] || "0.0" + end + + def chromium_based? + true + end + + def match? + ua.match?(/DingTalk/) + end + end +end diff --git a/lib/browser/safari.rb b/lib/browser/safari.rb index ee15c1e7..0c814def 100644 --- a/lib/browser/safari.rb +++ b/lib/browser/safari.rb @@ -25,6 +25,8 @@ def match? !opera? && !samsung_browser? && !huawei_browser? && + !wework_browser? && + !ding_talk_browser? && !miui_browser? && !duck_duck_go? && !yandex? && diff --git a/lib/browser/wework_browser.rb b/lib/browser/wework_browser.rb new file mode 100644 index 00000000..b8265c7c --- /dev/null +++ b/lib/browser/wework_browser.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module Browser + class WeworkBrowser < Base + def id + :wework_browser + end + + def name + "WeworkBrowser" + end + + def full_version + ua[%r{wxwork/([\d.]+)}, 1] || "0.0" + end + + def match? + ua.match?(/wxwork/) + end + end +end diff --git a/test/unit/wework_browser_test.rb b/test/unit/wework_browser_test.rb new file mode 100644 index 00000000..cf285d51 --- /dev/null +++ b/test/unit/wework_browser_test.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require "test_helper" + +class WeworkBrowserTest < Minitest::Test + test "detects Wework Browser" do + browser = Browser.new(Browser["WEWORK_BROWSER"]) + assert browser.wework_browser? + refute browser.safari? + refute browser.chrome? + assert_equal "Wework Browser", browser.name + assert_equal :wework_browser, browser.id + end + + test "detects correct version" do + browser = Browser.new(Browser["WEWORK_BROWSER"]) + assert_equal "10.1.2.300", browser.full_version + assert_equal "10", browser.version + end + + test "detects version by range" do + browser = Browser.new(Browser["WEWORK_BROWSER"]) + assert browser.huawei_browser?(%w[>=10 <11]) + end +end