Class: LinuxNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/birdy/linux_notifier.rb

Constant Summary collapse

DISPLAY_TIME_SECONDS =
5

Instance Method Summary collapse

Constructor Details

#initializeLinuxNotifier

Returns a new instance of LinuxNotifier.



5
6
7
8
# File 'lib/birdy/linux_notifier.rb', line 5

def initialize
  @notify = RBus.session_bus.get_object('org.freedesktop.Notifications', 
    '/org/freedesktop/Notifications')
end

Instance Method Details

#show(image_path, name, message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/birdy/linux_notifier.rb', line 10

def show(image_path, name, message)
  app_name = 'birdy'
  replaces_id = 0
  app_icon = image_path
  summary = name
  body = wrap_links(message)
  actions = []
  hints = {}
  expire_timeout = DISPLAY_TIME_SECONDS * 1000

  @notify.Notify(app_name, replaces_id, app_icon, summary, body, actions, 
                 hints, expire_timeout)
  sleep DISPLAY_TIME_SECONDS
end


25
26
27
28
29
30
# File 'lib/birdy/linux_notifier.rb', line 25

def wrap_links(text)
  text.gsub(%r{ ( https?:// | www\. ) [^\s<]+ }x) do
    href = $&
    "<a href='" + href + "'>" + href + "</a>"
  end
end