Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Option to also use growl_notify gem #99

Merged
merged 5 commits into from

4 participants

@johnbintz

growl_notify is a gem that uses AppleScript, the recommended approach, rather than the growlnotify CLI app, which is what the growl gem uses, to make Growl notifications. This change checks for growl_notify and then growl and uses the first one found. I've been running this fork for a few days with no problems, but I think it needs wider testing, since growl_notify is still pretty new.

lib/guard/notifier.rb
((12 lines not shown))
rescue LoadError
turn_off
- UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
+ UI.info "Please install growl or growl_notify gem for Mac OS X notification support and add it to your Gemfile"
@rymai Owner
rymai added a note

I suggest "Please install growl_notify or growl gem..." (keeping the same order as for the requires and in the README.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@rymai
Owner

That's pretty cool, I'll give it a try!

@rymai
Owner

I tried quickly yesterday and it didn't work, is there any extra configuration to make it work? (I think not but...)

@johnbintz

The gem's still fairly new, so it hasn't been too widely tested yet. I'll talk with the creator today and see if we can figure out what's going on. Are notifications actually reaching GrowlNotify.send_notification on your setup?

@rymai
Owner

Actually, it works well when Notifier.notify is called in the context of Guard, but not when it's not in its context (like in the guard-rspec formatters for example).

I tried to find why but no result yet.

@rymai
Owner

The issue seems to be in the GrowlNotify.config block since a puts before the block is displayed but a put just after the block is not (on guard-rspec results)...

@scottdavis

so growl_notify uses the apple script interface to talk to growl though the appscript gem. by doing this it requires that you follow the growl pattern of registering one application name per "Application" trying to modify the application name after it has been registered with growl will result in your notification to not being sent ex: johnbintz@e53036a#L0R54

Allowing people to define a custom application name is bad and it goes against the growl security "best practices" and hence will not work if you try to change the application name. The growl gem gets around this by using the growlnotify command which the growl team specifically states that it should not be used as a dependency in projects and is for debugging only and in so i believe it just throws the application name away since in the growl preferences it is registered as growlnotify

growl_notify gem gives you the ability to have your application show up as a registered app in the growl preferences and it works with the native applescript driver these are the core differences.

@thibaudgg
Owner

If growl_notify is the good way to use Growl what do you think of completely remove the growl gem support?

@johnbintz

Ideally, I'd love to not need the growl gem. growl_notify has been working well for me on my machine, and I'd like to get a little more "real-world" testing on the combination before I can confidently say, "Yes, remove growl." I'll play with it this week on a few other various Mac systems and see the results.

@thibaudgg
Owner

Ok perfect, good idea. Please try particularly the guard-rspec (with the embed growl formatter) and with the --notify false guard option. Thanks

@johnbintz

OK I just took this for a spin on a few other Macs I had available and growl_notify worked correctly with guard-rspec, and notifications didn't appear at all with --notify false. @rymai, can you try out the latest changes and see if they are working for you now?

@johnbintz

Just FYI, here's the test project I put together to test growl_notify with guard-rspec, to save you the trouble of putting something together yourselves: https://github.com/johnbintz/guard-growl_notify-test

@scottdavis

just to post the obvious but growl_notify does require that they have a xcode in stalled incase that is a deal killer

@thibaudgg
Owner

@jetviper21 @johnbintz @rymai are you think it's a issue? I suppose every Guard mac users have Xcode installed, no?

@johnbintz

If they're using rb-fsevent with Guard (and folks should be), they already need Xcode, right?

@thibaudgg
Owner

yeah, good point :)

@rymai
Owner

Let's do this?! :P

@johnbintz

Works for me, it's been solid for me for a month now. If people complain, we can switch it back.

@thibaudgg thibaudgg merged commit 3c32661 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 28, 2011
  1. @johnbintz

    add support for growl_notify

    johnbintz authored
  2. @johnbintz
  3. @johnbintz

    update README

    johnbintz authored
Commits on Jul 1, 2011
  1. @johnbintz
Commits on Jul 6, 2011
  1. @johnbintz
This page is out of date. Refresh to see the latest.
View
2  Gemfile
@@ -8,7 +8,7 @@ require 'rbconfig'
if RbConfig::CONFIG['target_os'] =~ /darwin/i
gem 'rb-fsevent', '>= 0.4.0', :require => false
- gem 'growl', '~> 1.0.3', :require => false
+ gem 'growl_notify', :require => false
end
if RbConfig::CONFIG['target_os'] =~ /linux/i
gem 'rb-inotify', '>= 0.8.5', :require => false
View
8 README.md
@@ -50,17 +50,17 @@ Install the rb-fsevent gem for [FSEvent](http://en.wikipedia.org/wiki/FSEvents)
$ gem install rb-fsevent
```
-Install the Growl gem if you want notification support:
+Install the growl_notify gem if you want notification support:
``` bash
-$ gem install growl
+$ gem install growl_notify
```
-And add them to your Gemfile:
+And add it to your Gemfile:
``` ruby
gem 'rb-fsevent'
-gem 'growl'
+gem 'growl_notify'
```
### On Linux
View
19 lib/guard/notifier.rb
@@ -4,6 +4,7 @@
module Guard
module Notifier
+ APPLICATION_NAME = "Guard"
def self.turn_off
ENV["GUARD_NOTIFY"] = 'false'
@@ -45,8 +46,11 @@ def self.enabled?
def self.notify_mac(title, message, image, options)
require_growl # need for guard-rspec formatter that is called out of guard scope
- default_options = { :title => title, :icon => image_path(image), :name => "Guard" }
- Growl.notify message, default_options.merge(options) if enabled?
+
+ options = { :description => message, :title => title, :icon => image_path(image), :application_name => APPLICATION_NAME }.merge(options)
+ options.delete(:name)
+
+ GrowlNotify.send_notification(options) if enabled?
end
def self.notify_linux(title, message, image, options)
@@ -90,10 +94,17 @@ def self.image_level(image)
end
def self.require_growl
- require 'growl'
+ require 'growl_notify'
+
+ if GrowlNotify.application_name != APPLICATION_NAME
+ GrowlNotify.config do |c|
+ c.notifications = c.default_notifications = [ APPLICATION_NAME ]
+ c.application_name = c.notifications.first
+ end
+ end
rescue LoadError
turn_off
- UI.info "Please install growl gem for Mac OS X notification support and add it to your Gemfile"
+ UI.info "Please install growl_notify gem for Mac OS X notification support and add it to your Gemfile"
end
def self.require_libnotify
View
95 spec/guard/notifier_spec.rb
@@ -20,17 +20,28 @@
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
end
- context "with the Growl library available" do
+ context "with the GrowlNotify library available" do
+ before do
+ module ::GrowlNotify
+ def self.config ; end
+ end
+ end
+
it "loads the library and enables the notifications" do
- subject.should_receive(:require).with('growl').and_return true
+ subject.should_receive(:require).with('growl_notify').and_return true
+ GrowlNotify.should_receive(:application_name).and_return ''
subject.turn_on
subject.should be_enabled
end
+
+ after do
+ Object.send(:remove_const, :GrowlNotify)
+ end
end
- context "without the Growl library available" do
+ context "without the GrowlNofity library available" do
it "disables the notifications" do
- subject.should_receive(:require).with('growl').and_raise LoadError
+ subject.should_receive(:require).with('growl_notify').and_raise LoadError
subject.turn_on
subject.should_not be_enabled
end
@@ -89,46 +100,54 @@
before do
RbConfig::CONFIG.should_receive(:[]).with('target_os').and_return 'darwin'
subject.stub(:require_growl)
- Object.send(:remove_const, :Growl) if defined?(Growl)
- Growl = Object.new
end
- after do
- Object.send(:remove_const, :Growl)
- end
+ context 'with growl_notify gem' do
+ before do
+ Object.send(:remove_const, :GrowlNotify) if defined?(GrowlNotify)
+ GrowlNotify = Object.new
+ end
- it "passes the notification to Growl" do
- Growl.should_receive(:notify).with("great",
- :title => "Guard",
- :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
- :name => "Guard"
- )
- subject.notify 'great', :title => 'Guard'
- end
+ after do
+ Object.send(:remove_const, :GrowlNotify)
+ end
- it "don't passes the notification to Growl if library is not available" do
- Growl.should_not_receive(:notify)
- subject.should_receive(:enabled?).and_return(true, false)
- subject.notify 'great', :title => 'Guard'
- end
+ it "passes the notification to Growl" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great'
+ )
+ subject.notify 'great', :title => 'Guard'
+ end
- it "allows additional notification options" do
- Growl.should_receive(:notify).with("great",
- :title => "Guard",
- :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
- :name => "Guard",
- :priority => 1
- )
- subject.notify 'great', :title => 'Guard', :priority => 1
- end
+ it "don't passes the notification to Growl if library is not available" do
+ GrowlNotify.should_not_receive(:send_notification)
+ subject.should_receive(:enabled?).and_return(true, false)
+ subject.notify 'great', :title => 'Guard'
+ end
- it "allows to overwrite a default notification option" do
- Growl.should_receive(:notify).with("great",
- :title => "Guard",
- :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
- :name => "Guard-Cucumber"
- )
- subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
+ it "allows additional notification options" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great',
+ :priority => 1
+ )
+ subject.notify 'great', :title => 'Guard', :priority => 1
+ end
+
+ it "throws out the application name since Guard should only use one Growl App Name while running" do
+ GrowlNotify.should_receive(:send_notification).with(
+ :title => "Guard",
+ :icon => Pathname.new(File.dirname(__FILE__)).join('../../images/success.png').to_s,
+ :application_name => "Guard",
+ :description => 'great'
+ )
+ subject.notify 'great', :title => 'Guard', :name => "Guard-Cucumber"
+ end
end
end
Something went wrong with that request. Please try again.