lib/terminal-notifier-guard.rb in terminal-notifier-guard-1.6.2 vs lib/terminal-notifier-guard.rb in terminal-notifier-guard-1.6.3

- old
+ new

@@ -1,20 +1,30 @@ 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" + VERSION = "1.6.3" ICONS_PATH = File.expand_path("../../icons", __FILE__) - GUARD_ICON = File.join(ICONS_PATH, 'guard.png') + GUARD_ICON = File.join(ICONS_PATH, 'Guard.icns') 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. def self.available? deprecation_check @@ -25,17 +35,21 @@ @available end # 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)) }) + options.merge!({ :contentImage=> GUARD_ICON, :appIcon => 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) end result = ''