diff --git a/lib/terminal-notifier-guard.rb b/lib/terminal-notifier-guard.rb index 1b448b0..a1e2bc7 100644 --- a/lib/terminal-notifier-guard.rb +++ b/lib/terminal-notifier-guard.rb @@ -1,7 +1,6 @@ module TerminalNotifier module Guard VERSION = "1.6.2" - BIN_PATH = "/usr/local/Cellar/terminal-notifier/1.6.1/terminal-notifier.app/Contents/MacOS/terminal-notifier" ICONS_PATH = File.expand_path("../../icons", __FILE__) GUARD_ICON = File.join(ICONS_PATH, 'guard.png') @@ -9,10 +8,21 @@ def self.osx_version Gem::Version.new(`sw_vers -productVersion`.strip) end + def self.terminal_notifier_version + return unless installed? + Gem::Version.new(`#{bin_path}`.lines.first.match(/\d\.\d\.\d/)[0]) + rescue + Gem::Version.new("0.0.0") + end + def self.deprecation_check if osx_version <= Gem::Version.new('10.8') raise "OSX 10.8 is no longer supported by this gem. Please revert to version <= 1.5.3." end + + if terminal_notifier_version < Gem::Version.new('1.6.0') + puts "Notice: Your terminal-notifier is older than what terminal-notifier-guard supports, consider upgrading." + end end # Returns wether or not the current platform is Mac OS X 10.8, or higher. @@ -27,14 +37,18 @@ def self.available? # Whether or not the terminal notifier is installed def self.installed? - return true if File.exist? BIN_PATH + File.exist? bin_path + end + + def self.bin_path + @@binary ||= `which terminal-notifier`.chomp end def self.execute(verbose, options) if available? && installed? options.merge!({ :appIcon => GUARD_ICON, :contentImage => icon(options.delete(:type)) }) - command = [BIN_PATH, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten] + command = [bin_path, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command) diff --git a/spec/terminal-notifier-guard_spec.rb b/spec/terminal-notifier-guard_spec.rb index 1df176a..b2963c2 100644 --- a/spec/terminal-notifier-guard_spec.rb +++ b/spec/terminal-notifier-guard_spec.rb @@ -11,7 +11,7 @@ describe "TerminalNotifier::Guard" do describe ".execute" do it "executes the tool with the given options" do - command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon] + command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command) @@ -21,7 +21,7 @@ end it "executes with the right icon path according to the type option" do - command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)] + command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command) @@ -31,7 +31,7 @@ end it "returns the result output of the command" do - TerminalNotifier::Guard.execute(false, 'help' => '').should == `'#{TerminalNotifier::Guard::BIN_PATH}' -help` + TerminalNotifier::Guard.execute(false, 'help' => '').should == `'#{TerminalNotifier::Guard.bin_path}' -help` end it "sends a notification" do @@ -87,7 +87,7 @@ describe ".failed" do it "executes with the 'failed' icon flag" do - command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:failed)] + command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:failed)] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command) @@ -99,7 +99,7 @@ describe ".success" do it "executes with the 'success' icon flag" do - command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)] + command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:success)] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command) @@ -111,7 +111,7 @@ describe ".pending" do it "executes with the 'pending' icon flag" do - command = [TerminalNotifier::Guard::BIN_PATH, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:pending)] + command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-appIcon', TerminalNotifier::Guard::GUARD_ICON, '-contentImage', TerminalNotifier::Guard.icon(:pending)] if RUBY_VERSION < '1.9' require 'shellwords' command = Shellwords.shelljoin(command)