Class: Fuso::App

Inherits:
Object
  • Object
show all
Includes:
Bubbletea::Model
Defined in:
lib/fuso/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApp

Returns a new instance of App.



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
# File 'lib/fuso/app.rb', line 30

def initialize
  @config = Config.load
  @session = Session.load

  @current_project = @config.default_project
  @current_category = @config.default_category

  # Timer state
  @tracking = false
  @active_project = nil
  @active_category = nil
  @timer_start = nil
  @timer_accumulated = 0  # seconds accumulated before pause

  # Screen state
  @screen = :main

  # Settings state
  @settings_focus = :projects
  @settings_index = 0
  @settings_input_mode = false
  @settings_input_buffer = ""
  @settings_message = nil

  # Report state
  @report_mode = :weekly
  @report_date = Date.today

  # Toast notification
  @toast = nil
  @toast_expires_at = nil

  # Views
  @main_view = Views::MainView.new
  @settings_view = Views::SettingsView.new
  @report_view = Views::ReportView.new

  # Heartbeat for suspend detection
  @heartbeat = Heartbeat.new
end

Instance Attribute Details

#active_categoryObject (readonly)

Returns the value of attribute active_category.



24
25
26
# File 'lib/fuso/app.rb', line 24

def active_category
  @active_category
end

#active_projectObject (readonly)

Returns the value of attribute active_project.



24
25
26
# File 'lib/fuso/app.rb', line 24

def active_project
  @active_project
end

#configObject (readonly)

Returns the value of attribute config.



22
23
24
# File 'lib/fuso/app.rb', line 22

def config
  @config
end

#current_categoryObject (readonly)

Returns the value of attribute current_category.



23
24
25
# File 'lib/fuso/app.rb', line 23

def current_category
  @current_category
end

#current_projectObject (readonly)

Returns the value of attribute current_project.



23
24
25
# File 'lib/fuso/app.rb', line 23

def current_project
  @current_project
end

#report_dateObject

Returns the value of attribute report_date.



27
28
29
# File 'lib/fuso/app.rb', line 27

def report_date
  @report_date
end

#report_modeObject

Returns the value of attribute report_mode.



27
28
29
# File 'lib/fuso/app.rb', line 27

def report_mode
  @report_mode
end

#sessionObject (readonly)

Returns the value of attribute session.



22
23
24
# File 'lib/fuso/app.rb', line 22

def session
  @session
end

#settings_focusObject

Returns the value of attribute settings_focus.



25
26
27
# File 'lib/fuso/app.rb', line 25

def settings_focus
  @settings_focus
end

#settings_indexObject

Returns the value of attribute settings_index.



25
26
27
# File 'lib/fuso/app.rb', line 25

def settings_index
  @settings_index
end

#settings_input_bufferObject

Returns the value of attribute settings_input_buffer.



26
27
28
# File 'lib/fuso/app.rb', line 26

def settings_input_buffer
  @settings_input_buffer
end

#settings_input_modeObject

Returns the value of attribute settings_input_mode.



25
26
27
# File 'lib/fuso/app.rb', line 25

def settings_input_mode
  @settings_input_mode
end

#settings_messageObject

Returns the value of attribute settings_message.



26
27
28
# File 'lib/fuso/app.rb', line 26

def settings_message
  @settings_message
end

#toastObject (readonly)

Returns the value of attribute toast.



28
29
30
# File 'lib/fuso/app.rb', line 28

def toast
  @toast
end

Instance Method Details

#active_elapsed_secondsObject



131
132
133
134
135
# File 'lib/fuso/app.rb', line 131

def active_elapsed_seconds
  return 0 unless @tracking && @timer_start

  @timer_accumulated + (Time.now - @timer_start).to_i
end

#current_timer_secondsObject



137
138
139
140
141
# File 'lib/fuso/app.rb', line 137

def current_timer_seconds
  return 0 unless @tracking && @timer_start

  (Time.now - @timer_start).to_i
end

#initObject



71
72
73
# File 'lib/fuso/app.rb', line 71

def init
  [self, schedule_tick]
end

#tracking?Boolean

Public state accessors

Returns:

  • (Boolean)


127
128
129
# File 'lib/fuso/app.rb', line 127

def tracking?
  @tracking
end

#update(message) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/fuso/app.rb', line 75

def update(message)
  case message
  when TickMessage
    # Check for suspend via heartbeat staleness
    if @tracking
      if (stale_time = @heartbeat.pulse)
        save_and_stop(at: stale_time)
        show_toast("Timer stopped — system was suspended")
      end
    end
    # Clear expired toast
    if @toast && @toast_expires_at && Time.now > @toast_expires_at
      @toast = nil
      @toast_expires_at = nil
    end
    # Timer ticks — just re-render
    [self, schedule_tick]
  when Bubbletea::WindowSizeMessage
    @width = message.width
    @height = message.height
    [self, nil]
  when Bubbletea::KeyMessage
    handle_key(message)
  else
    [self, nil]
  end
end

#viewObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/fuso/app.rb', line 103

def view
  content = case @screen
            when :main
              @main_view.render(self)
            when :settings
              @settings_view.render(self)
            when :report
              @report_view.render(self)
            end

  # Append toast notification if present
  if @toast
    content += "\n\n" + Styles.toast.render(@toast)
  end

  if @width && @height
    Lipgloss.place(@width, @height, :center, :center, content)
  else
    content
  end
end