Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #64 from stereobooster/master

Windows notifications
  • Loading branch information...
commit 973aba4375b2ac4ad1bdc5ea1f8fb2481f05843a 2 parents 6a77f01 + ad3def3
@thibaudgg thibaudgg authored
View
1  Gemfile
@@ -15,4 +15,5 @@ end
if Config::CONFIG['target_os'] =~ /mswin|mingw/i
gem 'win32console', :require => false
gem 'rb-fchange', '>= 0.0.2', :require => false
+ gem 'rb-notifu', '>= 0.0.4', :require => false
end
View
24 lib/guard/notifier.rb
@@ -16,6 +16,8 @@ def self.turn_on
require_growl
when /linux/i
require_libnotify
+ when /mswin|mingw/i
+ require_rbnotifu
end
end
@@ -30,6 +32,9 @@ def self.notify(message, options = {})
when /linux/i
require_libnotify # need for guard-rspec formatter that is called out of guard scope
Libnotify.show :body => message, :summary => title, :icon_path => image_path(image)
+ when /mswin|mingw/i
+ require_rbnotifu
+ Notifu.show :message => message, :title => title, :type => image_level(image), :time => 3
end
end
end
@@ -55,6 +60,19 @@ def self.image_path(image)
end
end
+ def self.image_level(image)
+ case image
+ when :failed
+ :error
+ when :pending
+ :warn
+ when :success
+ :info
+ else
+ :info
+ end
+ end
+
def self.require_growl
require 'growl'
rescue LoadError
@@ -69,5 +87,11 @@ def self.require_libnotify
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
end
+ def self.require_rbnotifu
+ require 'rb-notifu'
+ rescue LoadError
+ turn_off
+ UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile"
+ end
end
end
View
16 spec/guard/notifier_spec.rb
@@ -36,6 +36,22 @@
it { should_not be_enabled }
end
end
+
+ if windows?
+ if rbnotifu_installed?
+ it "uses rb-notifu on Windows" do
+ @result = -1
+ Notifu::show :message => "great", :title => 'Guard' do |status|
+ @result = status
+ end
+ sleep 1.5
+ Notifu::ERRORS.include?(@result).should be_false
+ end
+ else
+ it { should_not be_enabled }
+ end
+ end
+
end
describe ".turn_off" do
View
7 spec/support/gems_helper.rb
@@ -10,4 +10,11 @@ def libnotify_installed?
true
rescue LoadError
false
+end
+
+def rbnotifu_installed?
+ require 'rb-notifu'
+ true
+rescue LoadError
+ false
end
Please sign in to comment.
Something went wrong with that request. Please try again.