Skip to content

Commit

Permalink
moving stuff around, updating things
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Jun 13, 2008
1 parent 90f693f commit 6331b3f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 29 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,11 @@
=== 1.1.0 / 2008-06-13

* 3 major enhancements

* Added click callbacks so that Meow can be notified of clicks.
* Added Meow.run() to block and wait for clicks
* Meow.import_image() returns an image suitable for icon use

=== 1.0.0 / 2008-06-05

* 1 major enhancement
Expand Down
8 changes: 7 additions & 1 deletion README.rdoc
Expand Up @@ -11,6 +11,12 @@ Send Growl notifications via Ruby.
meep = Meow.new('Meow Test')
meep.notify('Title', 'Description')

## Handle clicks
meep.notify('Click Me', 'Do it!') do
puts "I got clicked!"
end
Meow.start # Start blocks

== REQUIREMENTS:

* Growl: http://growl.info
Expand All @@ -28,7 +34,7 @@ Thanks to the Growl team! This code is heavily based on their ruby example.

(The MIT License)

Copyright (c) 2008 Aaron Patterson
Copyright (c) 2008 Aaron Patterson, Evan Phoenix, Eric Hodel

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Expand Up @@ -2,7 +2,9 @@

require 'rubygems'
require './vendor/hoe.rb'
require './lib/meow.rb'

$LOAD_PATH << File.join(File.dirname(__FILE__), 'lib')
require 'meow'

Hoe.new('meow', Meow::VERSION) do |p|
p.readme = 'README.rdoc'
Expand Down
30 changes: 3 additions & 27 deletions lib/meow.rb
@@ -1,7 +1,5 @@
require 'osx/cocoa'

# This sets up shared state properly that Cocoa uses.
OSX::NSApplication.sharedApplication
require 'meow/notifier'

class Meow
VERSION = '1.0.0'
Expand All @@ -17,30 +15,8 @@ class Meow
GROWL_NOTIFICATION_TIMED_OUT = "GrowlTimedOut!"
GROWL_KEY_CLICKED_CONTEXT = "ClickedContext"

# addObserver can only be used with subclasses of NSObject, so we use this
# one.
class Notifier < OSX::NSObject
def setup
@callbacks = {}
end

def add(prc)
pos = prc.object_id
@callbacks[pos] = prc
return pos
end

def clicked(notification)
idx = notification.userInfo[GROWL_KEY_CLICKED_CONTEXT].to_i
begin
if block = @callbacks[idx]
block.call
end
ensure
@callbacks.delete idx
end
end
end
# This sets up shared state properly that Cocoa uses.
@@application = OSX::NSApplication.sharedApplication

# Holds blocks waiting for clicks
@@callbacks = Notifier.new
Expand Down
26 changes: 26 additions & 0 deletions lib/meow/notifier.rb
@@ -0,0 +1,26 @@
class Meow
# addObserver can only be used with subclasses of NSObject, so we use this
# one.
class Notifier < OSX::NSObject
def setup
@callbacks = {}
end

def add(prc)
pos = prc.object_id
@callbacks[pos] = prc
return pos
end

def clicked(notification)
idx = notification.userInfo[GROWL_KEY_CLICKED_CONTEXT].to_i
begin
if block = @callbacks[idx]
block.call
end
ensure
@callbacks.delete idx
end
end
end
end
14 changes: 14 additions & 0 deletions test/test_meow.rb
Expand Up @@ -46,4 +46,18 @@ def test_import_image
meep.notify('Aaron', 'Icon', :icon => icon)
}
end

def test_clicks_work
$RUBYCOCOA_SUPPRESS_EXCEPTION_LOGGING = true
block_called = false
assert_raises(RuntimeError) {
meep = Meow.new('Meow Test')
meep.notify('Click', 'Here') do
block_called = true
raise 'I do not know how to get run to stop blocking!'
end
Meow.run
}
assert block_called
end
end

0 comments on commit 6331b3f

Please sign in to comment.