Class: Domodoro::Client
- Inherits:
-
Object
- Object
- Domodoro::Client
- Defined in:
- lib/domodoro/client.rb
Class Method Summary collapse
- .connected ⇒ Object
- .connected=(value) ⇒ Object
- .current_action ⇒ Object
- .current_action=(action) ⇒ Object
- .next_action ⇒ Object
- .next_action=(action) ⇒ Object
- .start(host, port = '9111') ⇒ Object
Class Method Details
.connected ⇒ Object
7 8 9 |
# File 'lib/domodoro/client.rb', line 7 def connected @connected end |
.connected=(value) ⇒ Object
11 12 13 |
# File 'lib/domodoro/client.rb', line 11 def connected=(value) @connected = true end |
.current_action ⇒ Object
15 16 17 |
# File 'lib/domodoro/client.rb', line 15 def current_action @current_action end |
.current_action=(action) ⇒ Object
19 20 21 |
# File 'lib/domodoro/client.rb', line 19 def current_action=(action) @current_action = action end |
.next_action ⇒ Object
23 24 25 |
# File 'lib/domodoro/client.rb', line 23 def next_action @next_action end |
.next_action=(action) ⇒ Object
27 28 29 |
# File 'lib/domodoro/client.rb', line 27 def next_action=(action) @next_action = action end |
.start(host, port = '9111') ⇒ Object
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 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/domodoro/client.rb', line 31 def start(host, port='9111') Config.load_client_configuration puts "#{Time.now} - Domodoro listening on #{host}:#{port}" puts "Visual notifications: #{Config.visual}" puts "Sound notifications: #{Config.sound}\n" EM.run do EM.connect(host, port) do |c| c.extend EM::P::ObjectProtocol def c.connection_completed puts " - Connected to server!" Client.connected = true end def c.receive_object(object) case object[:current_action].last when :start Client.work when :stop Client.break when :lunch Client.lunch when :go_home Client.home end Client.current_action = object[:current_action] Client.next_action = object[:next_action] puts end end EM.add_periodic_timer(1) do EM.next_tick do if Client.connected && Client.current_action print_status else puts 'Cannot connect to server. Is it running?' end end end end end |