Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加 wework 和 dingtalk 浏览器 #532

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/browser/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
4 changes: 4 additions & 0 deletions lib/browser/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/chrome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def match?
!sputnik? &&
!samsung_browser? &&
!huawei_browser? &&
!wework_browser? &&
!ding_talk_browser? &&
!miui_browser? &&
!maxthon? &&
!qq? &&
Expand Down
25 changes: 25 additions & 0 deletions lib/browser/ding_talk_browser.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/browser/safari.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def match?
!opera? &&
!samsung_browser? &&
!huawei_browser? &&
!wework_browser? &&
!ding_talk_browser? &&
!miui_browser? &&
!duck_duck_go? &&
!yandex? &&
Expand Down
21 changes: 21 additions & 0 deletions lib/browser/wework_browser.rb
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions test/unit/wework_browser_test.rb
Original file line number Diff line number Diff line change
@@ -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