forked from discourse/discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchrome_installed_checker.rb
42 lines (32 loc) · 1.16 KB
/
chrome_installed_checker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# frozen_string_literal: true
require "rbconfig"
class ChromeInstalledChecker
class ChromeError < StandardError
end
class ChromeVersionError < ChromeError
end
class ChromeNotInstalled < ChromeError
end
class ChromeVersionTooLow < ChromeError
end
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;")
binary ||= "chromium" if system("command -v chromium >/dev/null;")
if !binary
raise ChromeNotInstalled.new(
"Chrome is not installed. Download from https://www.google.com/chrome/browser/desktop/index.html",
)
end
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")
raise ChromeVersionTooLow.new("Chrome 59 or higher is required")
end
end
end