Class: Timely::Application

Inherits:
Object
  • Object
show all
Includes:
Rcurses, Rcurses::Cursor, Rcurses::Input, UI::Panes
Defined in:
lib/timely/ui/application.rb

Instance Method Summary collapse

Methods included from UI::Panes

#create_panes, #setup_display

Constructor Details

#initializeApplication

Returns a new instance of Application.



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/timely/ui/application.rb', line 15

def initialize
  @db = Database.new
  @config = Config.new
  @running = false
  @selected_date = Date.today
  @selected_event_index = 0
  now = Time.now
  @selected_slot = now.hour * 2 + (now.min >= 30 ? 1 : 0)
  @slot_offset = [@selected_slot - 5, 0].max  # Show a few rows above current time
  @events_by_date = {}
  @_weather_date = Date.today
end

Instance Method Details

#runObject



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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/timely/ui/application.rb', line 28

def run
  Rcurses.init!
  Rcurses.clear_screen

  setup_display
  create_panes

  load_events_for_range

  # Auto-import ICS files from incoming directory
  incoming_count = Sources::IcsFile.watch_incoming(@db)
  load_events_for_range if incoming_count > 0

  render_all

  # Start background sync poller for Google Calendar
  @poller = Sync::Poller.new(@db, @config)
  @poller.start

  # Flush stdin before loop
  $stdin.getc while $stdin.wait_readable(0)

  @running = true
  loop do
    chr = getchr(2, flush: false)
    if chr
      handle_input(chr)
    else
      # No input received (timeout); check if poller has new data
      if @poller&.needs_refresh?
        @poller.clear_refresh_flag
        load_events_for_range
        render_all
      end
      # Check notifications on idle (runs inexpensively)
      Notifications.check_and_notify(@db) rescue nil
      # Refresh weather on new day
      today = Date.today
      if @_weather_date != today
        @_weather_date = today
        @weather_forecast = nil
        @_weather_fetched_at = nil
        load_events_for_range
        render_all
      end
      # Check for Heathrow goto trigger
      check_heathrow_goto
    end
    break unless @running
  end
ensure
  @poller&.stop
  Cursor.show
end