notifier 0.5.2 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.rubocop.yml +10 -0
- data/Gemfile +2 -0
- data/LICENSE.md +20 -0
- data/README.md +59 -55
- data/Rakefile +6 -1
- data/lib/notifier/hud.rb +32 -0
- data/lib/notifier/kdialog.rb +5 -1
- data/lib/notifier/knotify.rb +16 -4
- data/lib/notifier/notify_send.rb +5 -1
- data/lib/notifier/osd_cat.rb +7 -3
- data/lib/notifier/placebo.rb +2 -0
- data/lib/notifier/snarl.rb +2 -0
- data/lib/notifier/terminal_notifier.rb +14 -3
- data/lib/notifier/version.rb +5 -3
- data/lib/notifier.rb +20 -15
- data/notifier.gemspec +18 -6
- data/test/notifier/notifier_test.rb +23 -3
- data/test/notifier/snarl_test.rb +2 -0
- data/test/test_helper.rb +6 -2
- metadata +60 -21
- data/.travis.yml +0 -12
- data/lib/notifier/adapters/gntp.rb +0 -87
- data/lib/notifier/adapters.rb +0 -5
- data/lib/notifier/gntp.rb +0 -37
- data/lib/notifier/growl.rb +0 -31
- data/resources/register-growl.scpt +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f11e00e55117bf997579f4d0cd0ba9acb4242d5e5045c519c36f938f637235d8
|
4
|
+
data.tar.gz: f4091e3ef9660c00ad6620dc45d648adb686174549eda5ecc33cf7e4e654da41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 155c248f28980870789ac3a679ce2a8a89434be67d91164ad19444b9f7ce7de2c4b1796f007f417bb14f01ae0ba26f7c0aa20fcf599ed800b67bd054932feb0f
|
7
|
+
data.tar.gz: 6ed42de3b14e5de5de1ce707f528203be37344afeb2c25ce394d36e28a959afa07cc6ec2957c601732e7ff1a94c69b5225f3283a3313e127e10ec332a3bfabe7
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
data/Gemfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Nando Vieira
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the 'Software'), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,21 +1,17 @@
|
|
1
1
|
# Notifier
|
2
2
|
|
3
|
-
[![Travis-CI](https://travis-ci.org/fnando/notifier.png)](https://travis-ci.org/fnando/notifier)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/fnando/notifier/badges/gpa.svg)](https://codeclimate.com/github/fnando/notifier)
|
5
|
-
[![Test Coverage](https://codeclimate.com/github/fnando/notifier/badges/coverage.svg)](https://codeclimate.com/github/fnando/notifier/coverage)
|
6
3
|
[![Gem](https://img.shields.io/gem/v/notifier.svg)](https://rubygems.org/gems/notifier)
|
7
4
|
[![Gem](https://img.shields.io/gem/dt/notifier.svg)](https://rubygems.org/gems/notifier)
|
8
5
|
|
9
|
-
Send system notifications on several platforms with a simple and unified API.
|
6
|
+
Send system notifications on several platforms with a simple and unified API.
|
7
|
+
Currently supports:
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
* Libnotify (Linux)
|
18
|
-
* Snarl (Windows)
|
9
|
+
- terminal-notifier (Notification Center wrapper for Mac OS X)
|
10
|
+
- Kdialog (Linux/KDE)
|
11
|
+
- Knotify (Linux/KDE)
|
12
|
+
- OSD Cat (Linux)
|
13
|
+
- Libnotify (Linux)
|
14
|
+
- Snarl (Windows)
|
19
15
|
|
20
16
|
## Installation
|
21
17
|
|
@@ -23,20 +19,14 @@ Send system notifications on several platforms with a simple and unified API. Cu
|
|
23
19
|
|
24
20
|
### Mac OS X
|
25
21
|
|
26
|
-
#### Growl
|
27
|
-
|
28
|
-
* Install Growl - http://growl.info/
|
29
|
-
* Install the growlnotify script located on the "Extras" directory
|
30
|
-
* Open the Growl Preference Panel (System > Growl) and activate "Listen for incoming notifications" and "Allow remote application registration" options on the Network tab.
|
31
|
-
|
32
22
|
#### terminal-notifier
|
33
23
|
|
34
|
-
|
24
|
+
- Install terminal-notifier - https://github.com/alloy/terminal-notifier
|
35
25
|
|
36
26
|
terminal-notifier also supports two additional flags:
|
37
27
|
|
38
|
-
|
39
|
-
|
28
|
+
- `subtitle`
|
29
|
+
- `sound`
|
40
30
|
|
41
31
|
See terminal-notifier's help for additional information.
|
42
32
|
|
@@ -44,18 +34,21 @@ See terminal-notifier's help for additional information.
|
|
44
34
|
|
45
35
|
If you're a linux guy, you can choose one of these methods:
|
46
36
|
|
47
|
-
|
48
|
-
|
49
|
-
|
37
|
+
- Install libnotify-bin and its dependencies:
|
38
|
+
`sudo aptitude install libnotify-bin`
|
39
|
+
- Install xosd-bin: `sudo aptitude install xosd-bin`
|
40
|
+
- KDE users don't need to install anything: Test Notifier will use +knotify+ or
|
41
|
+
+kdialog+.
|
50
42
|
|
51
43
|
### Windows
|
52
44
|
|
53
|
-
|
54
|
-
|
45
|
+
- Install Snarl: download from http://www.fullphat.net
|
46
|
+
- Install ruby-snarl: `gem install ruby-snarl`
|
55
47
|
|
56
48
|
## Usage
|
57
49
|
|
58
|
-
Notifier will try to detect which notifiers are available in your system. So you
|
50
|
+
Notifier will try to detect which notifiers are available in your system. So you
|
51
|
+
can just send a message:
|
59
52
|
|
60
53
|
```ruby
|
61
54
|
Notifier.notify(
|
@@ -67,25 +60,38 @@ Notifier.notify(
|
|
67
60
|
|
68
61
|
Not all notifiers support the image option, therefore it will be ignored.
|
69
62
|
|
70
|
-
If your system support more than one notifier, you can specify which one you
|
63
|
+
If your system support more than one notifier, you can specify which one you
|
64
|
+
prefer:
|
71
65
|
|
72
66
|
```ruby
|
73
67
|
Notifier.default_notifier = :notify_send
|
74
68
|
```
|
75
69
|
|
76
|
-
|
70
|
+
Alternatively, you can set the default notifier by using the `NOTIFIER` env var.
|
71
|
+
The following example assumes `test_notifier` is configured on this Rails
|
72
|
+
project. The env var has precedence of `Notifier.default_notifier`.
|
73
|
+
|
74
|
+
```console
|
75
|
+
$ NOTIFIER=hud rails test
|
76
|
+
```
|
77
|
+
|
78
|
+
The available names are `terminal_notifier`, `kdialog`, `knotify`,
|
79
|
+
`notify_send`, `osd_cat`, and `snarl`.
|
77
80
|
|
78
|
-
There are several helper methods that you can use in order to retrieve
|
81
|
+
There are several helper methods that you can use in order to retrieve
|
82
|
+
notifiers.
|
79
83
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
84
|
+
- `Notifier.notifier`: return the first supported notifier
|
85
|
+
- `Notifier.notifiers`: return all notifiers
|
86
|
+
- `Notifier.supported_notifiers`: return only supported notifiers
|
87
|
+
- `Notifier.from_name(name)`: find notifier by its name
|
88
|
+
- `Notifier.supported_notifier_from_name(name)`: find a supported notifier by
|
89
|
+
its name
|
85
90
|
|
86
91
|
## Creating custom notifiers
|
87
92
|
|
88
|
-
To create a new notifier, just create a module on `Notifier` namespace that
|
93
|
+
To create a new notifier, just create a module on `Notifier` namespace that
|
94
|
+
implements the following interface:
|
89
95
|
|
90
96
|
```ruby
|
91
97
|
module Notifier
|
@@ -101,7 +107,7 @@ end
|
|
101
107
|
|
102
108
|
## Maintainer
|
103
109
|
|
104
|
-
|
110
|
+
- Nando Vieira - https://nandovieira.com
|
105
111
|
|
106
112
|
## Contributors
|
107
113
|
|
@@ -111,21 +117,19 @@ https://github.com/fnando/notifier/graphs/contributors
|
|
111
117
|
|
112
118
|
(The MIT License)
|
113
119
|
|
114
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
IN
|
129
|
-
|
130
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
131
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
120
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
121
|
+
this software and associated documentation files (the 'Software'), to deal in
|
122
|
+
the Software without restriction, including without limitation the rights to
|
123
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
124
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
125
|
+
subject to the following conditions:
|
126
|
+
|
127
|
+
The above copyright notice and this permission notice shall be included in all
|
128
|
+
copies or substantial portions of the Software.
|
129
|
+
|
130
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
131
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
132
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
133
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
134
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
135
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "bundler/gem_tasks"
|
2
4
|
require "rake/testtask"
|
5
|
+
require "rubocop/rake_task"
|
3
6
|
|
4
7
|
Rake::TestTask.new(:test) do |t|
|
5
8
|
t.libs << "test"
|
@@ -7,4 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
7
10
|
t.warning = false
|
8
11
|
end
|
9
12
|
|
10
|
-
|
13
|
+
RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
task default: %i[test rubocop]
|
data/lib/notifier/hud.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Notifier
|
4
|
+
module Hud
|
5
|
+
extend self
|
6
|
+
|
7
|
+
def supported?
|
8
|
+
Notifier.os?(/darwin/) && hud_bin
|
9
|
+
end
|
10
|
+
|
11
|
+
def hud_bin
|
12
|
+
@hud_bin ||= [
|
13
|
+
"/Applications/hud.app/Contents/MacOS/cli",
|
14
|
+
"~/Applications/hud.app/Contents/MacOS/cli"
|
15
|
+
].first {|path| File.expand_path(path) }
|
16
|
+
end
|
17
|
+
|
18
|
+
def notify(options)
|
19
|
+
command = [
|
20
|
+
hud_bin,
|
21
|
+
"--title",
|
22
|
+
options[:title].to_s,
|
23
|
+
"--message",
|
24
|
+
options[:message].to_s,
|
25
|
+
"--symbol-name",
|
26
|
+
options[:image].to_s
|
27
|
+
]
|
28
|
+
|
29
|
+
Thread.new { system(*command) }.join
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/notifier/kdialog.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module Kdialog
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which kdialog > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
data/lib/notifier/knotify.rb
CHANGED
@@ -1,16 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module Knotify
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`ps -Al | grep dcop` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
10
14
|
command = [
|
11
|
-
"dcop",
|
12
|
-
|
13
|
-
"",
|
15
|
+
"dcop",
|
16
|
+
"knotify",
|
17
|
+
"default",
|
18
|
+
"notify",
|
19
|
+
"eventname",
|
20
|
+
options[:title].to_s,
|
21
|
+
options[:message].to_s,
|
22
|
+
"",
|
23
|
+
"",
|
24
|
+
"16",
|
25
|
+
"2"
|
14
26
|
]
|
15
27
|
|
16
28
|
Thread.new { system(*command) }.join
|
data/lib/notifier/notify_send.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module NotifySend
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which notify-send > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
data/lib/notifier/osd_cat.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module OsdCat
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/(linux|freebsd)/) &&
|
8
|
+
Notifier.os?(/(linux|freebsd)/) &&
|
9
|
+
`which osd_cat > /dev/null` &&
|
10
|
+
$CHILD_STATUS == 0
|
7
11
|
end
|
8
12
|
|
9
13
|
def notify(options)
|
@@ -18,11 +22,11 @@ module Notifier
|
|
18
22
|
"--align", "center",
|
19
23
|
"--font", "-bitstream-bitstream charter-bold-r-*-*-*-350-*-*-*-*-*-*",
|
20
24
|
"--delay", "5",
|
21
|
-
"--outline", "4"
|
25
|
+
"--outline", "4"
|
22
26
|
]
|
23
27
|
|
24
28
|
Thread.new do
|
25
|
-
Open3.popen3(*command) do |stdin,
|
29
|
+
Open3.popen3(*command) do |stdin, _stdout, _stderr|
|
26
30
|
stdin.puts options[:message]
|
27
31
|
stdin.close
|
28
32
|
end
|
data/lib/notifier/placebo.rb
CHANGED
data/lib/notifier/snarl.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Notifier
|
2
4
|
module TerminalNotifier
|
3
5
|
extend self
|
4
6
|
|
5
7
|
def supported?
|
6
|
-
Notifier.os?(/darwin/) && `which terminal-notifier` &&
|
8
|
+
Notifier.os?(/darwin/) && `which terminal-notifier` && $CHILD_STATUS == 0
|
7
9
|
end
|
8
10
|
|
9
11
|
def notify(options)
|
@@ -18,9 +20,18 @@ module Notifier
|
|
18
20
|
|
19
21
|
# -sound with an empty string (e.g., "") will trigger the
|
20
22
|
# default sound so we need to check for it.
|
21
|
-
|
23
|
+
if options[:sound]
|
24
|
+
command.concat([
|
25
|
+
"-sound",
|
26
|
+
options.fetch(:sound, "default").to_s
|
27
|
+
])
|
28
|
+
end
|
22
29
|
|
23
|
-
Thread.new
|
30
|
+
Thread.new do
|
31
|
+
Open3.popen3(*command) do |_stdin, _stdout, _stderr|
|
32
|
+
# noop
|
33
|
+
end
|
34
|
+
end.join
|
24
35
|
end
|
25
36
|
end
|
26
37
|
end
|
data/lib/notifier/version.rb
CHANGED
data/lib/notifier.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "open3"
|
2
4
|
require "socket"
|
3
5
|
require "digest/md5"
|
4
6
|
require "timeout"
|
5
7
|
require "rbconfig"
|
8
|
+
require "English"
|
9
|
+
require "net/http"
|
6
10
|
|
7
11
|
module Notifier
|
8
|
-
require "notifier/growl"
|
9
|
-
require "notifier/gntp"
|
10
12
|
require "notifier/snarl"
|
13
|
+
require "notifier/hud"
|
11
14
|
require "notifier/osd_cat"
|
12
15
|
require "notifier/knotify"
|
13
16
|
require "notifier/kdialog"
|
@@ -15,7 +18,6 @@ module Notifier
|
|
15
18
|
require "notifier/placebo"
|
16
19
|
require "notifier/terminal_notifier"
|
17
20
|
require "notifier/version"
|
18
|
-
require "notifier/adapters"
|
19
21
|
|
20
22
|
extend self
|
21
23
|
|
@@ -23,8 +25,13 @@ module Notifier
|
|
23
25
|
attr_accessor :default_notifier
|
24
26
|
end
|
25
27
|
|
28
|
+
def skip_constants
|
29
|
+
@skip_constants ||= %w[Placebo Adapters Version]
|
30
|
+
end
|
31
|
+
|
26
32
|
def notifier
|
27
|
-
supported_notifier_from_name(default_notifier) ||
|
33
|
+
supported_notifier_from_name(ENV.fetch("NOTIFIER", default_notifier)) ||
|
34
|
+
supported_notifiers.first
|
28
35
|
end
|
29
36
|
|
30
37
|
def notify(options)
|
@@ -32,34 +39,32 @@ module Notifier
|
|
32
39
|
end
|
33
40
|
|
34
41
|
def notifiers
|
35
|
-
constants.
|
36
|
-
const_get(name) unless
|
37
|
-
end
|
42
|
+
constants.filter_map do |name|
|
43
|
+
const_get(name) unless skip_constants.include?(name.to_s)
|
44
|
+
end + [Placebo]
|
38
45
|
end
|
39
46
|
|
40
47
|
def supported_notifiers
|
41
|
-
notifiers.select
|
48
|
+
notifiers.select(&:supported?)
|
42
49
|
end
|
43
50
|
|
44
51
|
def from_name(name)
|
45
52
|
const_get(classify(name.to_s))
|
46
|
-
rescue
|
53
|
+
rescue StandardError
|
47
54
|
nil
|
48
55
|
end
|
49
56
|
|
50
57
|
def supported_notifier_from_name(name)
|
51
58
|
notifier = from_name(name)
|
52
|
-
notifier
|
59
|
+
notifier&.supported? ? notifier : nil
|
53
60
|
end
|
54
61
|
|
55
62
|
def os?(regex)
|
56
63
|
RUBY_PLATFORM =~ regex || RbConfig::CONFIG["host_os"] =~ regex
|
57
64
|
end
|
58
65
|
|
59
|
-
private
|
60
|
-
|
61
|
-
|
62
|
-
string.gsub(/_(.)/sm) { "#{$1.upcase}" }
|
63
|
-
.gsub(/^(.)/) { "#{$1.upcase}" }
|
66
|
+
private def classify(string)
|
67
|
+
string.gsub(/_(.)/sm) { Regexp.last_match(1).upcase.to_s }
|
68
|
+
.gsub(/^(.)/) { Regexp.last_match(1).upcase.to_s }
|
64
69
|
end
|
65
70
|
end
|
data/notifier.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "./lib/notifier/version"
|
2
4
|
|
3
5
|
Gem::Specification.new do |s|
|
@@ -5,20 +7,30 @@ Gem::Specification.new do |s|
|
|
5
7
|
s.version = Notifier::Version::STRING
|
6
8
|
s.platform = Gem::Platform::RUBY
|
7
9
|
s.authors = ["Nando Vieira"]
|
8
|
-
s.email = ["fnando.
|
10
|
+
s.email = ["me@fnando.com"]
|
9
11
|
s.homepage = "http://rubygems.org/gems/notifier"
|
10
|
-
s.summary = "Send system notifications on several platforms with a
|
12
|
+
s.summary = "Send system notifications on several platforms with a " \
|
13
|
+
"simple and unified API. Currently supports Libnotify, " \
|
14
|
+
"OSD, KDE (Knotify and Kdialog) and Snarl"
|
11
15
|
s.description = s.summary
|
16
|
+
s.required_ruby_version = ">= 2.7"
|
17
|
+
s.metadata["rubygems_mfa_required"] = "true"
|
12
18
|
|
13
19
|
s.files = `git ls-files`.split("\n")
|
14
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
|
22
|
+
File.basename(f)
|
23
|
+
end
|
16
24
|
s.require_paths = ["lib"]
|
17
25
|
|
18
|
-
s.requirements << "
|
26
|
+
s.requirements << "terminal-notifier, Libnotify, OSD, KDE (Knotify and " \
|
27
|
+
"Kdialog) or Snarl"
|
19
28
|
|
20
29
|
s.add_development_dependency "minitest-utils"
|
21
|
-
s.add_development_dependency "rake"
|
22
30
|
s.add_development_dependency "mocha"
|
23
|
-
s.add_development_dependency "
|
31
|
+
s.add_development_dependency "rake"
|
32
|
+
s.add_development_dependency "rubocop"
|
33
|
+
s.add_development_dependency "rubocop-fnando"
|
34
|
+
s.add_development_dependency "simplecov"
|
35
|
+
s.add_development_dependency "test_notifier"
|
24
36
|
end
|
@@ -1,12 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "test_helper"
|
2
4
|
|
3
5
|
class NotifierTest < Minitest::Test
|
4
6
|
setup do
|
5
7
|
Notifier.notifiers.each do |notifier|
|
6
|
-
|
8
|
+
unless notifier == Notifier::Placebo
|
9
|
+
notifier.stubs(:supported?).returns(false)
|
10
|
+
end
|
7
11
|
end
|
8
12
|
|
9
13
|
Notifier.default_notifier = nil
|
14
|
+
ENV.delete("NOTIFIER")
|
15
|
+
end
|
16
|
+
|
17
|
+
teardown do
|
18
|
+
Notifier.default_notifier = :hud
|
10
19
|
end
|
11
20
|
|
12
21
|
test "retrieves list of supported notifiers" do
|
@@ -32,6 +41,17 @@ class NotifierTest < Minitest::Test
|
|
32
41
|
assert_equal Notifier::Knotify, Notifier.notifier
|
33
42
|
end
|
34
43
|
|
44
|
+
test "prefers default notifier using env var" do
|
45
|
+
ENV["NOTIFIER"] = "knotify"
|
46
|
+
|
47
|
+
Notifier::Snarl.stubs(:supported?).returns(true)
|
48
|
+
Notifier::Knotify.stubs(:supported?).returns(true)
|
49
|
+
|
50
|
+
Notifier.default_notifier = :snarl
|
51
|
+
|
52
|
+
assert_equal Notifier::Knotify, Notifier.notifier
|
53
|
+
end
|
54
|
+
|
35
55
|
test "sends notification" do
|
36
56
|
params = {
|
37
57
|
title: "Some title",
|
@@ -46,7 +66,7 @@ class NotifierTest < Minitest::Test
|
|
46
66
|
end
|
47
67
|
|
48
68
|
test "retrieves list of all notifiers" do
|
49
|
-
assert_equal
|
69
|
+
assert_equal 8, Notifier.notifiers.size
|
50
70
|
end
|
51
71
|
|
52
72
|
test "considers Placebo as fallback notifier" do
|
@@ -56,7 +76,7 @@ class NotifierTest < Minitest::Test
|
|
56
76
|
test "returns notifier by its name" do
|
57
77
|
assert_equal Notifier::OsdCat, Notifier.from_name(:osd_cat)
|
58
78
|
assert_equal Notifier::NotifySend, Notifier.from_name(:notify_send)
|
59
|
-
assert_equal Notifier::
|
79
|
+
assert_equal Notifier::Hud, Notifier.from_name(:hud)
|
60
80
|
end
|
61
81
|
|
62
82
|
test "returns notifier by its name when supported" do
|
data/test/notifier/snarl_test.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,11 +1,15 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "simplecov"
|
4
|
+
SimpleCov.start
|
3
5
|
|
4
6
|
require "bundler/setup"
|
5
7
|
require "notifier"
|
6
8
|
require "minitest/utils"
|
7
9
|
require "minitest/autorun"
|
8
10
|
|
11
|
+
Notifier.default_notifier = :hud
|
12
|
+
|
9
13
|
module Snarl
|
10
14
|
def self.show_message(*)
|
11
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest-utils
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mocha
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,21 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-fnando
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
44
72
|
requirements:
|
45
73
|
- - ">="
|
@@ -53,7 +81,21 @@ dependencies:
|
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: test_notifier
|
57
99
|
requirement: !ruby/object:Gem::Requirement
|
58
100
|
requirements:
|
59
101
|
- - ">="
|
@@ -67,23 +109,21 @@ dependencies:
|
|
67
109
|
- !ruby/object:Gem::Version
|
68
110
|
version: '0'
|
69
111
|
description: Send system notifications on several platforms with a simple and unified
|
70
|
-
API. Currently supports
|
112
|
+
API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
71
113
|
email:
|
72
|
-
- fnando.
|
114
|
+
- me@fnando.com
|
73
115
|
executables: []
|
74
116
|
extensions: []
|
75
117
|
extra_rdoc_files: []
|
76
118
|
files:
|
77
119
|
- ".gitignore"
|
78
|
-
- ".
|
120
|
+
- ".rubocop.yml"
|
79
121
|
- Gemfile
|
122
|
+
- LICENSE.md
|
80
123
|
- README.md
|
81
124
|
- Rakefile
|
82
125
|
- lib/notifier.rb
|
83
|
-
- lib/notifier/
|
84
|
-
- lib/notifier/adapters/gntp.rb
|
85
|
-
- lib/notifier/gntp.rb
|
86
|
-
- lib/notifier/growl.rb
|
126
|
+
- lib/notifier/hud.rb
|
87
127
|
- lib/notifier/kdialog.rb
|
88
128
|
- lib/notifier/knotify.rb
|
89
129
|
- lib/notifier/notify_send.rb
|
@@ -93,14 +133,14 @@ files:
|
|
93
133
|
- lib/notifier/terminal_notifier.rb
|
94
134
|
- lib/notifier/version.rb
|
95
135
|
- notifier.gemspec
|
96
|
-
- resources/register-growl.scpt
|
97
136
|
- test/notifier/notifier_test.rb
|
98
137
|
- test/notifier/snarl_test.rb
|
99
138
|
- test/test_helper.rb
|
100
139
|
homepage: http://rubygems.org/gems/notifier
|
101
140
|
licenses: []
|
102
|
-
metadata:
|
103
|
-
|
141
|
+
metadata:
|
142
|
+
rubygems_mfa_required: 'true'
|
143
|
+
post_install_message:
|
104
144
|
rdoc_options: []
|
105
145
|
require_paths:
|
106
146
|
- lib
|
@@ -108,20 +148,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
108
148
|
requirements:
|
109
149
|
- - ">="
|
110
150
|
- !ruby/object:Gem::Version
|
111
|
-
version: '
|
151
|
+
version: '2.7'
|
112
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
153
|
requirements:
|
114
154
|
- - ">="
|
115
155
|
- !ruby/object:Gem::Version
|
116
156
|
version: '0'
|
117
157
|
requirements:
|
118
|
-
-
|
119
|
-
|
120
|
-
|
121
|
-
signing_key:
|
158
|
+
- terminal-notifier, Libnotify, OSD, KDE (Knotify and Kdialog) or Snarl
|
159
|
+
rubygems_version: 3.3.7
|
160
|
+
signing_key:
|
122
161
|
specification_version: 4
|
123
162
|
summary: Send system notifications on several platforms with a simple and unified
|
124
|
-
API. Currently supports
|
163
|
+
API. Currently supports Libnotify, OSD, KDE (Knotify and Kdialog) and Snarl
|
125
164
|
test_files:
|
126
165
|
- test/notifier/notifier_test.rb
|
127
166
|
- test/notifier/snarl_test.rb
|
data/.travis.yml
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
cache: bundler
|
3
|
-
sudo: false
|
4
|
-
notifications:
|
5
|
-
email: false
|
6
|
-
rvm:
|
7
|
-
- 2.3.0
|
8
|
-
- '2.2'
|
9
|
-
- '2.1'
|
10
|
-
env:
|
11
|
-
global:
|
12
|
-
secure: mYd3r1SEZJcirOFNjNe75vMNjYJ/UHDLZAsEeCQQcI4Na03au53Pr02waJKPdXXV8JnakaYMDNBc4kOXnk3v0ytgINnvNXnObjPT2KUPvQKLUhXq2Q/BrWS4CFihihznZHAQFgeTVbDm/brLWH61+JwDlQ2kEo6OGSAZ8ZV/PV8=
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Notifier
|
2
|
-
module Adapters
|
3
|
-
class GNTP
|
4
|
-
attr_accessor :application_name
|
5
|
-
attr_accessor :host
|
6
|
-
attr_accessor :port
|
7
|
-
attr_accessor :password
|
8
|
-
|
9
|
-
def initialize(options = {})
|
10
|
-
if options.kind_of?(String)
|
11
|
-
options = {name: options}
|
12
|
-
end
|
13
|
-
|
14
|
-
@application_name = options.fetch(:name, "GNTP/Ruby")
|
15
|
-
@host = options.fetch(:host, "127.0.0.1")
|
16
|
-
@port = options.fetch(:port, 23053)
|
17
|
-
@password = options.fetch(:password, nil)
|
18
|
-
end
|
19
|
-
|
20
|
-
def line_break(number = 1)
|
21
|
-
"\r\n" * number
|
22
|
-
end
|
23
|
-
|
24
|
-
def write(*contents)
|
25
|
-
contents.map! do |content|
|
26
|
-
content.force_encoding("utf-8") rescue content
|
27
|
-
end
|
28
|
-
|
29
|
-
socket = TCPSocket.open(host, port)
|
30
|
-
message = [*contents, line_break(2)].join(line_break)
|
31
|
-
socket.write(message)
|
32
|
-
|
33
|
-
"".tap do |response|
|
34
|
-
while chunk = socket.gets
|
35
|
-
break if chunk == line_break
|
36
|
-
response << chunk
|
37
|
-
end
|
38
|
-
|
39
|
-
socket.close
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
def notify(options)
|
44
|
-
name = options.fetch(:name, "notification")
|
45
|
-
register(name)
|
46
|
-
|
47
|
-
icon = fetch_icon(options[:icon])
|
48
|
-
|
49
|
-
write "GNTP/1.0 NOTIFY NONE",
|
50
|
-
"Application-Name: #{application_name}",
|
51
|
-
"Notification-Name: #{name}",
|
52
|
-
"Notification-Title: #{options[:title]}",
|
53
|
-
"Notification-Text: #{options[:message]}",
|
54
|
-
"Notification-Icon: x-growl-resource://#{icon[:identifier]}",
|
55
|
-
"Notification-Sticky: #{bool options[:sticky]}",
|
56
|
-
nil,
|
57
|
-
"Identifier: #{icon[:identifier]}",
|
58
|
-
"Length: #{icon[:size]}",
|
59
|
-
nil,
|
60
|
-
icon[:contents]
|
61
|
-
end
|
62
|
-
|
63
|
-
def fetch_icon(path)
|
64
|
-
contents = File.open(path, "rb") {|f| f.read }
|
65
|
-
|
66
|
-
{
|
67
|
-
identifier: Digest::MD5.hexdigest(contents),
|
68
|
-
contents: contents,
|
69
|
-
size: contents.bytesize
|
70
|
-
}
|
71
|
-
end
|
72
|
-
|
73
|
-
def bool(boolean)
|
74
|
-
{true => "Yes", false => "No"}[boolean]
|
75
|
-
end
|
76
|
-
|
77
|
-
def register(name)
|
78
|
-
write "GNTP/1.0 REGISTER NONE",
|
79
|
-
"Application-Name: #{application_name}",
|
80
|
-
"Notifications-count: 1",
|
81
|
-
nil,
|
82
|
-
"Notification-Name: #{name}",
|
83
|
-
"Notification-Enabled: True"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
data/lib/notifier/adapters.rb
DELETED
data/lib/notifier/gntp.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Notifier
|
2
|
-
module GNTP extend self
|
3
|
-
def supported?
|
4
|
-
Timeout.timeout(1) { TCPSocket.new(host, port).close }
|
5
|
-
true
|
6
|
-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Timeout::Error
|
7
|
-
false
|
8
|
-
end
|
9
|
-
|
10
|
-
def port
|
11
|
-
ENV.fetch("GNTP_PORT", 23053)
|
12
|
-
end
|
13
|
-
|
14
|
-
def host
|
15
|
-
ENV["GNTP_HOST"] || ssh_connection || "127.0.0.1"
|
16
|
-
end
|
17
|
-
|
18
|
-
def ssh_connection
|
19
|
-
ENV["SSH_CONNECTION"][/^([^ ]+)/, 1] if ENV["SSH_CONNECTION"]
|
20
|
-
end
|
21
|
-
|
22
|
-
def notify(options)
|
23
|
-
gntp = Adapters::GNTP.new({
|
24
|
-
name: "test_notifier",
|
25
|
-
host: host,
|
26
|
-
port: port
|
27
|
-
})
|
28
|
-
|
29
|
-
gntp.notify({
|
30
|
-
name: "status",
|
31
|
-
title: options[:title],
|
32
|
-
message: options[:message],
|
33
|
-
icon: options[:image]
|
34
|
-
})
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
data/lib/notifier/growl.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module Notifier
|
2
|
-
module Growl
|
3
|
-
extend self
|
4
|
-
|
5
|
-
SCRIPT = File.dirname(__FILE__) + "/../../resources/register-growl.scpt"
|
6
|
-
FILE = File.expand_path("~/.test_notifier-growl")
|
7
|
-
|
8
|
-
def supported?
|
9
|
-
Notifier.os?(/darwin/) && `which growlnotify` && $? == 0
|
10
|
-
end
|
11
|
-
|
12
|
-
def notify(options)
|
13
|
-
register
|
14
|
-
command = [
|
15
|
-
"growlnotify",
|
16
|
-
"--name", "test_notifier",
|
17
|
-
"--image", options.fetch(:image, "").to_s,
|
18
|
-
"--priority", "2",
|
19
|
-
"--message", options[:message].to_s,
|
20
|
-
options[:title].to_s
|
21
|
-
]
|
22
|
-
|
23
|
-
Thread.new { system(*command) }.join
|
24
|
-
end
|
25
|
-
|
26
|
-
def register
|
27
|
-
return if File.file?(FILE)
|
28
|
-
system "osascript #{SCRIPT} > #{FILE}"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
Binary file
|