[MacRuby-devel] Added NSNotification support to HotCocoa
Laurent Sansonetti
lsansonetti at apple.com
Fri Sep 19 11:45:03 PDT 2008
On Sep 19, 2008, at 6:22 AM, Richard Kilmer wrote:
> I added the ability to easily support notification posting and
> subscribing in HotCocoa:
>
[...]
Great!
$ cat t2.rb
require 'hotcocoa'
include HotCocoa
application do
on_notification :distributed => true do |note|
puts note.description
end
end
$ ./miniruby -I./lib t2.rb
NSConcreteNotification 0x185f9b0 {name = O3EngineChanged; object =
brte*04271800; userInfo = {
DisplayID = 69670912;
EngineType = 1651668069;
}}
[...]
NSConcreteNotification 0x16cb8e0 {name = com.apple.iTunes.playerInfo;
object = com.apple.iTunes.player; userInfo = {
Album = Damnation;
Artist = Opeth;
Genre = "Death Metal";
Location = "file://localhost/Volumes/Data/music/Opeth/Damnation/03%20Death%20whispered%20a%20lullaby.mp3
";
Name = "Death whispered a lullaby";
"Player State" = Playing;
"Store URL" = "itms://itunes.com/link?n=Death%20whispered%20a%20lullaby&an=Opeth&pn=Damnation
";
"Total Time" = 349805;
"Track Count" = 8;
"Track Number" = 3;
Year = 2003;
}}
[...]
I also checked that posting a distributed notification works.
$ cat t3.rb
require 'hotcocoa'
include HotCocoa
application do
notification :name => ARGV.first, :info => {'123' =>
'456'}, :distributed => true
end
Note, I had to apply the following patch before.
Index: lib/hotcocoa/mappings/notification.rb
===================================================================
--- lib/hotcocoa/mappings/notification.rb (revision 608)
+++ lib/hotcocoa/mappings/notification.rb (working copy)
@@ -5,12 +5,12 @@
def alloc_with_options(options)
if options.delete(:post)
if options.delete(:distributed)
-
NSDistributedNotificationCenter.defaultCenter.postNotificationWithName
options.delete(:name), object:options.delete(:object),
userInfo:options.delete(:info), deliverImmediately:
(options.delete(:immediately) == true)
+
NSDistributedNotificationCenter.defaultCenter.postNotificationName
options.delete(:name), object:options.delete(:object),
userInfo:options.delete(:info), deliverImmediately:
(options.delete(:immediately) == true)
else
- NSNotificationCenter.defaultCenter.postNotificationWithName
options.delete(:name), object:options.delete(:object),
userInfo:options.delete(:info)
+ NSNotificationCenter.defaultCenter.postNotificationName
options.delete(:name), object:options.delete(:object),
userInfo:options.delete(:info)
end
else
- NSNotification.notificationWithName options.delete(:name),
object:options.delete(:object), userInfo:options.delete(:info)
+ NSNotification.notificationName options.delete(:name),
object:options.delete(:object), userInfo:options.delete(:info)
end
end
Great work!
Laurent
More information about the MacRuby-devel
mailing list