/
client.rb
58 lines (49 loc) · 1.24 KB
/
client.rb
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'notify'
module Domodoro
class Client
class << self
def start(host, port)
Config.load
EM.run do
EM.connect(host, port) do |c|
c.extend EM::P::LineText2
def c.receive_line(line)
case line
when /start/
puts "#{Time.now} - Starting pomodoro!"
Client.work
when /stop/
puts "#{Time.now} - Pomdoro break!"
Client.break
end
end
end
end
end
def work
EM.defer do
if Config.visual
Notify.notify "Domodoro", "Time to work!"
end
if Config.sound
system("afplay #{path_to('start.wav')}")
end
end
end
def break
EM.defer do
if Config.visual
Notify.notify "Domodoro", "Take a 5 min. break."
end
if Config.sound
system("afplay #{path_to('stop.wav')} && afplay #{path_to('stop.mp3')}")
end
end
end
private
def path_to(asset)
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'assets', asset))
end
end
end
end