Class: Fliewr::Core
- Inherits:
-
Object
- Object
- Fliewr::Core
- Defined in:
- lib/fliewr/core.rb
Instance Method Summary collapse
- #ask_update(time_ahead = 0) ⇒ Object
- #human_time(time) ⇒ Object
-
#initialize ⇒ Core
constructor
A new instance of Core.
- #main ⇒ Object
- #quit ⇒ Object
- #start_timer ⇒ Object
- #timestamp ⇒ Object
- #update ⇒ Object
Constructor Details
Instance Method Details
#ask_update(time_ahead = 0) ⇒ Object
40 41 42 |
# File 'lib/fliewr/core.rb', line 40 def ask_update(time_ahead = 0) @requires_update_at = + time_ahead end |
#human_time(time) ⇒ Object
55 56 57 58 59 |
# File 'lib/fliewr/core.rb', line 55 def human_time(time) seconds = time.modulo(SECONDS_PER_MINUTE) minutes = (time - seconds) / SECONDS_PER_MINUTE "%d:%02d" % [minutes, seconds] end |
#main ⇒ Object
61 62 63 |
# File 'lib/fliewr/core.rb', line 61 def main Gtk::main end |
#quit ⇒ Object
65 66 67 68 69 |
# File 'lib/fliewr/core.rb', line 65 def quit Gtk::main_quit ensure $cfg.save end |
#start_timer ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fliewr/core.rb', line 44 def start_timer @@timeout = Gtk::timeout_add(1000) do sec_to_next_update = @requires_update_at.to_i - if sec_to_next_update < 0 update else $gui..push 0, "%s to update" % human_time(sec_to_next_update) end end end |
#timestamp ⇒ Object
36 37 38 |
# File 'lib/fliewr/core.rb', line 36 def Time.now.to_i end |
#update ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fliewr/core.rb', line 21 def update Gtk.timeout_remove(@@timeout) if @@timeout $gui..push 0, "updating..." Thread.new do ask_update $cfg.get(:update_interval) * 60 photos = $api.update $cfg.get(:max_photos) $gui.refresh_with photos @last_updated_at = end start_timer rescue Exception => e Alert.new @nsid, e., e.backtrace end |