2021-06-20 23:28:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "rbconfig"
|
|
|
|
|
|
|
|
class ChromeInstalledChecker
|
2022-03-19 06:00:06 -04:00
|
|
|
class ChromeError < StandardError; end
|
|
|
|
class ChromeVersionError < ChromeError; end
|
|
|
|
class ChromeNotInstalled < ChromeError; end
|
|
|
|
class ChromeVersionTooLow < ChromeError; end
|
2021-06-20 23:28:48 -04: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 06:00:06 -04:00
|
|
|
binary ||= "chromium" if system("command -v chromium >/dev/null;")
|
2021-06-20 23:28:48 -04: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 06:00:06 -04:00
|
|
|
version = `\"#{binary}\" --version`
|
|
|
|
version_match = version.match(/[\d\.]+/)
|
|
|
|
|
|
|
|
if !version_match
|
|
|
|
raise ChromeError.new("Can't get the #{binary} version")
|
|
|
|
end
|
|
|
|
|
|
|
|
if Gem::Version.new(version_match[0]) < Gem::Version.new("59")
|
2021-06-20 23:28:48 -04:00
|
|
|
raise ChromeVersionTooLow.new("Chrome 59 or higher is required")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|