2021-06-21 11:28:48 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rbconfig"
|
|
|
|
|
|
|
|
class ChromeInstalledChecker
|
2022-03-19 18:00:06 +08:00
|
|
|
class ChromeError < StandardError
|
|
|
|
end
|
2023-12-15 23:46:04 +08:00
|
|
|
|
2022-03-19 18:00:06 +08:00
|
|
|
class ChromeVersionError < ChromeError
|
|
|
|
end
|
2023-12-15 23:46:04 +08:00
|
|
|
|
2022-03-19 18:00:06 +08:00
|
|
|
class ChromeNotInstalled < ChromeError
|
|
|
|
end
|
2023-12-15 23:46:04 +08:00
|
|
|
|
2022-03-19 18:00:06 +08:00
|
|
|
class ChromeVersionTooLow < ChromeError
|
|
|
|
end
|
2021-06-21 11:28:48 +08:00
|
|
|
|
|
|
|
def self.run
|
|
|
|
if RbConfig::CONFIG["host_os"][/darwin|mac os/]
|
|
|
|
binary = "/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome"
|
|
|
|
elsif system("command -v google-chrome-stable >/dev/null;")
|
|
|
|
binary = "google-chrome-stable"
|
|
|
|
end
|
|
|
|
binary ||= "google-chrome" if system("command -v google-chrome >/dev/null;")
|
2022-03-19 18:00:06 +08:00
|
|
|
binary ||= "chromium" if system("command -v chromium >/dev/null;")
|
2021-06-21 11:28:48 +08:00
|
|
|
|
|
|
|
if !binary
|
|
|
|
raise ChromeNotInstalled.new(
|
|
|
|
"Chrome is not installed. Download from https://www.google.com/chrome/browser/desktop/index.html",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-03-19 18:00:06 +08:00
|
|
|
version = `\"#{binary}\" --version`
|
|
|
|
version_match = version.match(/[\d\.]+/)
|
|
|
|
|
|
|
|
raise ChromeError.new("Can't get the #{binary} version") if !version_match
|
|
|
|
|
|
|
|
if Gem::Version.new(version_match[0]) < Gem::Version.new("59")
|
2021-06-21 11:28:48 +08:00
|
|
|
raise ChromeVersionTooLow.new("Chrome 59 or higher is required")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|