public
Description: A Gitk-like application written in RubyCocoa that looks like it belongs on a Mac. See the wiki for downloads and screenshots.
Homepage: http://alternateidea.com
Clone URL: git://github.com/Caged/gitnub.git
Click here to lend your support to: gitnub and make a donation at www.pledgie.com !
gitnub / lib / osx_notify.rb
100644 37 lines (28 sloc) 0.916 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Yanked from http://github.com/evanphx/osx-notify/tree/master
module OSX
  class Notify < OSX::NSObject
 
    @@notifications = []
 
    def self.on(name, &block)
      notify = new()
 
      @@notifications << notify
 
      notify.name = name
      notify.block = block
 
      c = OSX::NSDistributedNotificationCenter.defaultCenter
      c.addObserver_selector_name_object_ notify, "call:", name, nil
      return notify
    end
 
    def self.send(name, opts)
      c = OSX::NSDistributedNotificationCenter.defaultCenter
      c.postNotificationName_object_userInfo_deliverImmediately_ name, nil, opts, true
    end
 
    attr_accessor :block, :name
 
    def call(notification)
      @block.call(notification.userInfo)
    end
 
    def delete!
      c = OSX::NSDistributedNotificationCenter.defaultCenter
      c.removeObserver_name_object_ self, @name, nil
      @@notifications.delete self
    end
  end
end