From 02448b857520ebc84de6b3d266575c8a7a6aa1ec Mon Sep 17 00:00:00 2001 From: slavic Date: Sat, 21 May 2011 02:19:42 +0300 Subject: [PATCH 1/3] windows notifiaction --- Gemfile | 1 + lib/guard/notifier.rb | 24 ++++++++++++++++++++++++ spec/guard/notifier_spec.rb | 19 +++++++++++++++++++ spec/support/gems_helper.rb | 7 +++++++ 4 files changed, 51 insertions(+) diff --git a/Gemfile b/Gemfile index bd1d194..2828b2a 100644 --- a/Gemfile +++ b/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', :require => false end diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 55ad56f..bbddd2e 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -15,6 +15,8 @@ module Guard require_growl when /linux/i require_libnotify + when /mswin|mingw/i + require_rbnotifu end end @@ -29,6 +31,9 @@ module Guard 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 + RbNotifu.show :message => message, :title => title, :type => image_level(image) end end end @@ -54,6 +59,19 @@ module Guard 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 @@ -68,5 +86,11 @@ module Guard UI.info "Please install libnotify gem for Linux notification support and add it to your Gemfile" end + def self.require_rbnotifu + require 'rbnotifu' + rescue LoadError + turn_off + UI.info "Please install rbnotifu gem for Windows notification support and add it to your Gemfile" + end end end \ No newline at end of file diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index d057a16..6c8dfb8 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -36,6 +36,21 @@ describe Guard::Notifier do it { should_not be_enabled } end end + + if windows? + if rbnotifu_installed? + it "uses rbnotifu on Windows" do + RbNotifu::show( + :message => "great", + :title => 'Guard', + :type => :info + ) + end + else + it { should_not be_enabled } + end + end + end describe ".turn_off" do @@ -49,6 +64,10 @@ describe Guard::Notifier do Libnotify.should_not_receive(:show) subject.notify 'great', :title => 'Guard' end + elsif windows? && rbnotifu_installed? + it "prevents the notifications" do + + end end it { should_not be_enabled } diff --git a/spec/support/gems_helper.rb b/spec/support/gems_helper.rb index 2ccf7fe..53b60cf 100644 --- a/spec/support/gems_helper.rb +++ b/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 \ No newline at end of file From 18d2db9ff1ff29a809e7fecf2b613a741813a470 Mon Sep 17 00:00:00 2001 From: slavic Date: Sun, 22 May 2011 00:47:02 +0300 Subject: [PATCH 2/3] windows notifiaction works (tested with guard-bundler) --- Gemfile | 2 +- lib/guard/notifier.rb | 6 +++--- spec/guard/notifier_spec.rb | 17 +++++++---------- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 2828b2a..675c4b3 100644 --- a/Gemfile +++ b/Gemfile @@ -15,5 +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', :require => false + gem 'rb-notifu', '>= 0.0.3', :require => false end diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index bbddd2e..93ea92e 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -33,7 +33,7 @@ module Guard Libnotify.show :body => message, :summary => title, :icon_path => image_path(image) when /mswin|mingw/i require_rbnotifu - RbNotifu.show :message => message, :title => title, :type => image_level(image) + RbNotifu.show :message => message, :title => title, :type => image_level(image), :display => 3000 end end end @@ -87,10 +87,10 @@ module Guard end def self.require_rbnotifu - require 'rbnotifu' + require 'rb-notifu' rescue LoadError turn_off - UI.info "Please install rbnotifu gem for Windows notification support and add it to your Gemfile" + UI.info "Please install rb-notifu gem for Windows notification support and add it to your Gemfile" end end end \ No newline at end of file diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 6c8dfb8..17dfdae 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -39,12 +39,13 @@ describe Guard::Notifier do if windows? if rbnotifu_installed? - it "uses rbnotifu on Windows" do - RbNotifu::show( - :message => "great", - :title => 'Guard', - :type => :info - ) + it "uses rb-notifu on Windows" do + @result = -1 + RbNotifu::show :message => "great", :title => 'Guard' do |status| + @result = status + end + sleep 1.5 + RbNotifu::ERRORS.include?(@result).should be_false end else it { should_not be_enabled } @@ -64,10 +65,6 @@ describe Guard::Notifier do Libnotify.should_not_receive(:show) subject.notify 'great', :title => 'Guard' end - elsif windows? && rbnotifu_installed? - it "prevents the notifications" do - - end end it { should_not be_enabled } From ad3def39e2047159ad87126a73b6546aa08941cc Mon Sep 17 00:00:00 2001 From: slavic Date: Sun, 22 May 2011 11:38:54 +0300 Subject: [PATCH 3/3] Changes connected with new version of rb-notifu --- Gemfile | 2 +- lib/guard/notifier.rb | 2 +- spec/guard/notifier_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 675c4b3..1386270 100644 --- a/Gemfile +++ b/Gemfile @@ -15,5 +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.3', :require => false + gem 'rb-notifu', '>= 0.0.4', :require => false end diff --git a/lib/guard/notifier.rb b/lib/guard/notifier.rb index 93ea92e..ed29eeb 100644 --- a/lib/guard/notifier.rb +++ b/lib/guard/notifier.rb @@ -33,7 +33,7 @@ module Guard Libnotify.show :body => message, :summary => title, :icon_path => image_path(image) when /mswin|mingw/i require_rbnotifu - RbNotifu.show :message => message, :title => title, :type => image_level(image), :display => 3000 + Notifu.show :message => message, :title => title, :type => image_level(image), :time => 3 end end end diff --git a/spec/guard/notifier_spec.rb b/spec/guard/notifier_spec.rb index 17dfdae..f7452bb 100644 --- a/spec/guard/notifier_spec.rb +++ b/spec/guard/notifier_spec.rb @@ -41,11 +41,11 @@ describe Guard::Notifier do if rbnotifu_installed? it "uses rb-notifu on Windows" do @result = -1 - RbNotifu::show :message => "great", :title => 'Guard' do |status| + Notifu::show :message => "great", :title => 'Guard' do |status| @result = status end sleep 1.5 - RbNotifu::ERRORS.include?(@result).should be_false + Notifu::ERRORS.include?(@result).should be_false end else it { should_not be_enabled }