Skip to content

Commit

Permalink
Merge pull request #64 from stereobooster/master
Browse files Browse the repository at this point in the history
Windows notifications
  • Loading branch information
thibaudgg committed May 28, 2011
2 parents 6a77f01 + ad3def3 commit 973aba4
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -15,4 +15,5 @@ end
if Config::CONFIG['target_os'] =~ /mswin|mingw/i if Config::CONFIG['target_os'] =~ /mswin|mingw/i
gem 'win32console', :require => false gem 'win32console', :require => false
gem 'rb-fchange', '>= 0.0.2', :require => false gem 'rb-fchange', '>= 0.0.2', :require => false
gem 'rb-notifu', '>= 0.0.4', :require => false
end end
24 changes: 24 additions & 0 deletions lib/guard/notifier.rb
Expand Up @@ -16,6 +16,8 @@ def self.turn_on
require_growl require_growl
when /linux/i when /linux/i
require_libnotify require_libnotify
when /mswin|mingw/i
require_rbnotifu
end end
end end


Expand All @@ -30,6 +32,9 @@ def self.notify(message, options = {})
when /linux/i when /linux/i
require_libnotify # need for guard-rspec formatter that is called out of guard scope 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) 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 end
end end
Expand All @@ -55,6 +60,19 @@ def self.image_path(image)
end end
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 def self.require_growl
require 'growl' require 'growl'
rescue LoadError rescue LoadError
Expand All @@ -69,5 +87,11 @@ def self.require_libnotify
UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile" UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile"
end 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
end end
16 changes: 16 additions & 0 deletions spec/guard/notifier_spec.rb
Expand Up @@ -36,6 +36,22 @@
it { should_not be_enabled } it { should_not be_enabled }
end end
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 end


describe ".turn_off" do describe ".turn_off" do
Expand Down
7 changes: 7 additions & 0 deletions spec/support/gems_helper.rb
Expand Up @@ -10,4 +10,11 @@ def libnotify_installed?
true true
rescue LoadError rescue LoadError
false false
end

def rbnotifu_installed?
require 'rb-notifu'
true
rescue LoadError
false
end end

0 comments on commit 973aba4

Please sign in to comment.