Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Make urgency configurable for libnotify/notifysend #270

Merged
merged 2 commits into from

2 participants

@viking

Also changes default urgency for libnotify to normal and low to match notifysend's new defaults.

@viking viking Make urgency configurable for libnotify/notifysend
- Change default urgency for libnotify to normal and low to match
  notifysend's defaults.
a2b35eb
@rymai
Owner

Thanks!

Could you please also reflect this update in the README under the "Guardfile DSL -> notification" section?

@viking

Is that sufficient? I can add more details if needed.

@rymai
Owner

I think that's enough, what do you think @netzpirat ?

@rymai rymai merged commit 9f589cd into guard:master
@rymai
Owner

Thanks! Added to CHANGELOG as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 28, 2012
  1. @viking

    Make urgency configurable for libnotify/notifysend

    viking authored
    - Change default urgency for libnotify to normal and low to match
      notifysend's defaults.
  2. @viking
This page is out of date. Refresh to see the latest.
View
2  README.md
@@ -630,7 +630,7 @@ Each notifier has a slightly different set of supported options:
notification :growl, :sticky => true, :host => '192.168.1.5', :password => 'secret'
notification :gntp, :sticky => true, :host => '192.168.1.5', :password => 'secret'
notification :growl_notify, :sticky => true, :priority => 0
-notification :libnotify, :timeout => 5, :transient => true, :append => false
+notification :libnotify, :timeout => 5, :transient => true, :append => false, :urgency => :critical
notification :notifu, :time => 5, :nosound => true, :xp => true
```
View
11 lib/guard/notifiers/libnotify.rb
@@ -17,7 +17,7 @@ module Notifier
# notification :libnotify
#
# @example Add the `:libnotify` notifier with configuration options to your `Guardfile`
- # notification :libnotify, :timeout => 5, :transient => true, :append => false
+ # notification :libnotify, :timeout => 5, :transient => true, :append => false, :urgency => :critical
#
module Libnotify
extend self
@@ -64,12 +64,13 @@ def available?(silent = false)
def notify(type, title, message, image, options = { })
require 'libnotify'
- ::Libnotify.show(DEFAULTS.merge(options).merge({
- :urgency => libnotify_urgency(type),
+ options = DEFAULTS.merge(options).merge({
:summary => title,
:body => message,
:icon_path => image
- }))
+ })
+ options[:urgency] ||= libnotify_urgency(type)
+ ::Libnotify.show(options)
end
private
@@ -83,8 +84,6 @@ def notify(type, title, message, image, options = { })
def libnotify_urgency(type)
case type
when 'failed'
- :critical
- when 'pending'
:normal
else
:low
View
7 lib/guard/notifiers/notifysend.rb
@@ -46,10 +46,11 @@ def available?(silent = false)
#
def notify(type, title, message, image, options = { })
command = "notify-send '#{title}' '#{message}'"
- system(to_command_string(command, SUPPORTED, DEFAULTS.merge(options).merge({
- :u => notifysend_urgency(type),
+ options = DEFAULTS.merge(options).merge({
:i => image
- })))
+ })
+ options[:u] ||= notifysend_urgency(type)
+ system(to_command_string(command, SUPPORTED, options))
end
private
View
10 spec/guard/notifiers/libnotify_spec.rb
@@ -45,7 +45,7 @@ def self.show(options) end
end
end
- describe '.nofify' do
+ describe '.notify' do
it 'requires the library again' do
subject.should_receive(:require).with('libnotify').and_return true
subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { })
@@ -72,7 +72,7 @@ def self.show(options) end
:transient => true,
:append => false,
:timeout => 5,
- :urgency => :normal,
+ :urgency => :critical,
:summary => 'Waiting',
:body => 'Waiting for something',
:icon_path => '/tmp/wait.png'
@@ -80,7 +80,8 @@ def self.show(options) end
subject.notify('pending', 'Waiting', 'Waiting for something', '/tmp/wait.png', {
:transient => true,
:append => false,
- :timeout => 5
+ :timeout => 5,
+ :urgency => :critical
})
end
@@ -89,13 +90,12 @@ def self.show(options) end
:transient => false,
:append => true,
:timeout => 3,
- :urgency => :critical,
+ :urgency => :normal,
:summary => 'Failed',
:body => 'Something failed',
:icon_path => '/tmp/fail.png'
})
subject.notify('failed', 'Failed', 'Something failed', '/tmp/fail.png', {
- :urgency => :extreme,
:summary => 'Duplicate title',
:body => 'Duplicate body',
:icon_path => 'Duplicate icon'
View
29 spec/guard/notifiers/notifysend_spec.rb
@@ -28,4 +28,33 @@ def self.show(options) end
end
end
end
+
+ describe '.notify' do
+ context 'without additional options' do
+ it 'shows the notification with the default options' do
+ subject.should_receive(:system).with do |command|
+ command.should include("notify-send 'Welcome' 'Welcome to Guard'")
+ command.should include("-i '/tmp/welcome.png'")
+ command.should include("-u 'low'")
+ command.should include("-t '3000'")
+ end
+ subject.notify('success', 'Welcome', 'Welcome to Guard', '/tmp/welcome.png', { })
+ end
+ end
+
+ context 'with additional options' do
+ it 'can override the default options' do
+ subject.should_receive(:system).with do |command|
+ command.should include("notify-send 'Waiting' 'Waiting for something'")
+ command.should include("-i '/tmp/wait.png'")
+ command.should include("-u 'critical'")
+ command.should include("-t '5'")
+ end
+ subject.notify('pending', 'Waiting', 'Waiting for something', '/tmp/wait.png', {
+ :t => 5,
+ :u => :critical
+ })
+ end
+ end
+ end
end
Something went wrong with that request. Please try again.