growlnotifier 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/growl.rb +11 -2
  2. data/test/growl_test.rb +21 -10
  3. metadata +2 -2
@@ -2,7 +2,7 @@ require 'osx/cocoa'
2
2
 
3
3
  module Growl
4
4
  class Notifier < OSX::NSObject
5
- VERSION = '1.0.1'
5
+ VERSION = '1.0.2'
6
6
 
7
7
  GROWL_IS_READY = "Lend Me Some Sugar; I Am Your Neighbor!"
8
8
  GROWL_NOTIFICATION_CLICKED = "GrowlClicked!"
@@ -27,6 +27,14 @@ module Growl
27
27
  attr_reader :application_name, :application_icon, :notifications, :default_notifications
28
28
  attr_accessor :delegate
29
29
 
30
+ # Set to +true+ if you want to receive delegate callback messages,
31
+ # <tt>growlNotifierClicked_context</tt> & <tt>growlNotifierTimedOut_context</tt>,
32
+ # without the need to specify a <tt>:click_context</tt>.
33
+ #
34
+ # The default is +false+, which means your application won't receive any delegate
35
+ # callback messages if the <tt>:click_context</tt> is omitted.
36
+ attr_accessor :always_callback
37
+
30
38
  # Registers the applications metadata and the notifications, that your application might send, to Growl.
31
39
  # The +default_notifications+ are notifications that will be enabled by default, the regular +notifications+ are
32
40
  # optional and should be enabled by the user in the Growl system preferences.
@@ -55,6 +63,7 @@ module Growl
55
63
  # * +options+ : specifies a few optional options:
56
64
  # * <tt>:sticky</tt> : indicates if the Grow notification should "stick" to the screen. Defaults to +false+.
57
65
  # * <tt>:priority</tt> : sets the priority level of the Growl notification. Defaults to 0.
66
+ # * <tt>:click_context</tt> : a string describing the context of the notification. This is send back to the delegate so you can check what kind of notification it was. If omitted, no delegate messages will be send. You can disable this behaviour by setting always_callback to +true+.
58
67
  # * <tt>:icon</tt> : specifies the icon to be used in the Growl notification. Defaults to the registered +application_icon+, see register for more info.
59
68
  #
60
69
  # Simple example:
@@ -92,7 +101,7 @@ module Growl
92
101
  @callbacks[callback.object_id] = callback
93
102
  context[:callback_object_id] = callback.object_id.to_s
94
103
  end
95
- dict[:NotificationClickContext] = context unless context.empty?
104
+ dict[:NotificationClickContext] = context if always_callback || !context.empty?
96
105
 
97
106
  notification_center.postNotificationName_object_userInfo_deliverImmediately(:GrowlNotification, nil, dict, true)
98
107
  end
@@ -97,7 +97,7 @@ describe "Growl::Notifier.sharedInstance" do
97
97
 
98
98
  before do
99
99
  set_variables!
100
-
100
+ @instance.always_callback = false
101
101
  @pid = 54231
102
102
  OSX::NSProcessInfo.processInfo.stubs(:processIdentifier).returns(@pid)
103
103
  end
@@ -150,6 +150,23 @@ describe "Growl::Notifier.sharedInstance" do
150
150
  @instance.notify(@notifications.first, 'title', 'description')
151
151
  end
152
152
 
153
+ it "should use the applications name as the click context if always_callback is set to true" do
154
+ @instance.always_callback = true
155
+
156
+ dict = {
157
+ :ApplicationName => @name,
158
+ :ApplicationPID => @pid,
159
+ :NotificationName => @notifications.first,
160
+ :NotificationTitle => 'title',
161
+ :NotificationDescription => 'description',
162
+ :NotificationPriority => 0,
163
+ :NotificationClickContext => {}
164
+ }
165
+
166
+ @center.expects(:postNotificationName_object_userInfo_deliverImmediately).with(:GrowlNotification, nil, dict, true)
167
+ @instance.notify(@notifications.first, 'title', 'description')
168
+ end
169
+
153
170
  it "should take a symbol instead of an integer to specify the priority level when sending a notification to Growl" do
154
171
  priority_table = { :very_low => -2, :moderate => -1, :normal => 0, :high => 1, :emergency => 2 }
155
172
 
@@ -191,8 +208,9 @@ describe "Growl::Notifier.sharedInstance" do
191
208
  @instance.onClicked(notification)
192
209
  end
193
210
 
194
- it "should send a message to the delegate if a notification was clicked with nil as the context if none was specified" do
195
- notification = stubbed_notification
211
+ it "should send a message to the delegate without a click_context if always_callback is enabled and no :click_context was specified" do
212
+ @instance.always_callback = true
213
+ notification = stubbed_notification({})
196
214
  assign_delegate.expects(:growlNotifierClicked_context).with(@instance, nil)
197
215
  @instance.onClicked(notification)
198
216
  end
@@ -221,13 +239,6 @@ describe "Growl::Notifier.sharedInstance" do
221
239
  @instance.onTimeout(notification)
222
240
  end
223
241
 
224
- it "should send a message to the delegate if a notification times out with nil as the context in none was specified" do
225
- notification = stubbed_notification
226
- assign_delegate.expects(:growlNotifierTimedOut_context).with(@instance, nil)
227
-
228
- @instance.onTimeout(notification)
229
- end
230
-
231
242
  it "should not send a message to the delegate if a notification times out but the delegate doesn't respond to the delegate method" do
232
243
  assign_delegate
233
244
  @instance.onTimeout(stubbed_notification)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: growlnotifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Satoshi Nakagawa
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-04 00:00:00 +09:00
13
+ date: 2008-11-21 00:00:00 +09:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency