module Guard::Notifier::Libnotify

def available?(silent = false)

Returns:
  • (Boolean) - the availability status

Parameters:
  • silent (Boolean) -- true if no error messages should be shown
def available?(silent = false)
  if RbConfig::CONFIG['host_os'] =~ /linux|freebsd|openbsd|sunos|solaris/
    require 'libnotify'
    true
  else
    ::Guard::UI.error 'The :libnotify notifier runs only on Linux, FreeBSD, OpenBSD and Solaris.' unless silent
    false
  end
rescue LoadError
  ::Guard::UI.error "Please add \"gem 'libnotify'\" to your Gemfile and run Guard with \"bundle exec\"." unless silent
  false
end

def libnotify_urgency(type)

Returns:
  • (Symbol) - the libnotify urgency

Parameters:
  • type (String) -- the Guard notification type
def libnotify_urgency(type)
  case type
  when 'failed'
    :critical
  when 'pending'
    :normal
  else
    :low
  end
end

def notify(type, title, message, image, options = { })

Options Hash: (**options)
  • timeout (Number, Boolean) -- the number of seconds to display (1.5 (s), 1000 (ms), false)
  • append (Boolean) -- append onto existing notification
  • transient (Boolean) -- keep the notifications around after display

Parameters:
  • options (Hash) -- additional notification library options
  • image (String) -- the path to the notification image
  • message (String) -- the notification message body
  • title (String) -- the notification title
  • type (String) -- the notification type. Either 'success', 'pending', 'failed' or 'notify'
def notify(type, title, message, image, options = { })
  require 'libnotify'
  ::Libnotify.show(DEFAULTS.merge(options).merge({
    :urgency   => libnotify_urgency(type),
    :summary   => title,
    :body      => message,
    :icon_path => image
  }))
end