2010-10-17 19:42:40 +00:00
|
|
|
require 'rbconfig'
|
2010-10-03 21:00:33 +00:00
|
|
|
require 'pathname'
|
|
|
|
|
|
|
|
module Guard
|
|
|
|
module Notifier
|
2011-04-10 20:32:29 +00:00
|
|
|
|
|
|
|
def self.turn_off
|
|
|
|
@disable = true
|
|
|
|
end
|
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def self.notify(message, options = {})
|
2011-04-10 20:32:29 +00:00
|
|
|
unless @disable || ENV["GUARD_ENV"] == "test"
|
2010-10-03 21:00:33 +00:00
|
|
|
image = options[:image] || :success
|
|
|
|
title = options[:title] || "Guard"
|
2010-10-17 19:42:40 +00:00
|
|
|
case Config::CONFIG['target_os']
|
|
|
|
when /darwin/i
|
2010-10-19 19:49:17 +00:00
|
|
|
if growl_installed?
|
|
|
|
Growl.notify message, :title => title, :icon => image_path(image), :name => "Guard"
|
|
|
|
end
|
2010-10-17 19:42:40 +00:00
|
|
|
when /linux/i
|
2010-10-19 19:49:17 +00:00
|
|
|
if libnotify_installed?
|
|
|
|
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
|
|
|
|
end
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
private
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
def self.image_path(image)
|
|
|
|
images_path = Pathname.new(File.dirname(__FILE__)).join('../../images')
|
|
|
|
case image
|
|
|
|
when :failed
|
|
|
|
images_path.join("failed.png").to_s
|
|
|
|
when :pending
|
|
|
|
images_path.join("pending.png").to_s
|
|
|
|
when :success
|
|
|
|
images_path.join("success.png").to_s
|
|
|
|
else
|
|
|
|
# path given
|
|
|
|
image
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-19 19:49:17 +00:00
|
|
|
def self.growl_installed?
|
|
|
|
@installed ||= begin
|
|
|
|
require 'growl'
|
|
|
|
true
|
|
|
|
rescue LoadError
|
2010-10-25 19:36:45 +00:00
|
|
|
UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
|
2010-10-19 19:49:17 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-19 19:49:17 +00:00
|
|
|
def self.libnotify_installed?
|
|
|
|
@installed ||= begin
|
|
|
|
require 'libnotify'
|
|
|
|
true
|
|
|
|
rescue LoadError
|
2010-10-25 19:36:45 +00:00
|
|
|
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
|
2010-10-19 19:49:17 +00:00
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
2011-04-10 20:32:29 +00:00
|
|
|
|
2010-10-03 21:00:33 +00:00
|
|
|
end
|
2011-04-29 22:40:12 +00:00
|
|
|
end
|