Permalink
Browse files

Merge pull request #3 from ijcd/gntp

Add support for ruby_gntp which is needed for Growl v1.3+
  • Loading branch information...
2 parents 50dafd6 + 70a8f4c commit 135f95bd4914ca399fa397dc1512ea71325be5b4 @flyerhzm committed Jan 12, 2012
Showing with 42 additions and 15 deletions.
  1. +2 −1 README.md
  2. +40 −14 lib/uniform_notifier/growl.rb
View
@@ -76,7 +76,8 @@ Growl Support
To get Growl support up-and-running, follow the steps below:
-* Install the ruby-growl gem: <code>gem install ruby-growl</code>
+* For Growl < v1.3, install the ruby-growl gem: <code>gem install ruby-growl</code>
+* For Growl v1.3+, install the ruby_gntp gem: <code>gem install ruby_gntp</code>
* Open the Growl preference pane in Systems Preferences
* Click the "Network" tab
* Make sure both "Listen for incoming notifications" and "Allow remote application registration" are checked. *Note*: If you set a password, you will need to set <code>UniformNotifier.growl_password = { :password => 'growl password' }</code> in the config file.
@@ -12,28 +12,54 @@ def self.out_of_channel_notify( message )
end
def self.setup_connection( growl )
+ setup_connection_growl(growl)
+ rescue LoadError
+ begin
+ setup_connection_gntp(growl)
+ rescue LoadError
+ @growl = nil
+ raise NotificationError.new( 'You must install the ruby-growl or the ruby_gntp gem to use Growl notification: `gem install ruby-growl` or `gem install ruby_gntp`' )
+ end
+ end
+
+ def self.setup_connection_growl( growl )
return unless growl
require 'ruby-growl'
@password = growl.instance_of?(Hash) ? growl[:password] : nil
- @growl = connect
+ @growl = ::Growl.new('localhost',
+ 'uniform_notifier',
+ [ 'uniform_notifier' ],
+ nil,
+ @password)
notify 'Uniform Notifier Growl has been turned on'
- rescue LoadError
- @growl = nil
- raise NotificationError.new( 'You must install the ruby-growl gem to use Growl notification: `gem install ruby-growl`' )
end
- private
- def self.connect
- ::Growl.new 'localhost',
- 'uniform_notifier',
- [ 'uniform_notifier' ],
- nil,
- @password
- end
+ def self.setup_connection_growl( growl )
+ return unless growl
+ require 'ruby_gntp'
+ @password = growl.instance_of?(Hash) ? growl[:password] : nil
+ @growl = GNTP.new('uniform_notifier', 'localhost', @password, 23053)
+ @growl.register({:notifications => [{
+ :name => 'uniform_notifier',
+ :enabled => true,
+ }]})
+
+ notify 'Uniform Notifier Growl has been turned on (using GNTP)'
+ end
+ private
def self.notify( message )
- @growl.notify( 'uniform_notifier', 'Uniform Notifier', message )
+ case @growl
+ when Growl
+ @growl.notify( 'uniform_notifier', 'Uniform Notifier', message )
+ when GNTP
+ @growl.notify({
+ :name => 'uniform_notifier',
+ :title => 'Uniform Notifier',
+ :text => message
+ })
+ end
end
+ end
end
-end

0 comments on commit 135f95b

Please sign in to comment.