46 lines
1 KiB
Go
46 lines
1 KiB
Go
|
package client
|
||
|
|
||
|
import (
|
||
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||
|
|
||
|
"github.com/charmbracelet/bubbles/key"
|
||
|
tea "github.com/charmbracelet/bubbletea"
|
||
|
)
|
||
|
|
||
|
// sends start/pause/resume based on the state of the pomodoro
|
||
|
func start_pause_resume(message GoTomato.ServerMessage) string {
|
||
|
if !message.Ongoing {
|
||
|
return "start"
|
||
|
}
|
||
|
if message.Paused {
|
||
|
return "resume"
|
||
|
} else {
|
||
|
return "pause"
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (a app) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||
|
switch msg := msg.(type) {
|
||
|
case GoTomato.ServerMessage:
|
||
|
a.pomodoro = msg
|
||
|
return a, a.waitForChannelSignal()
|
||
|
case tea.KeyMsg:
|
||
|
switch {
|
||
|
case key.Matches(msg, a.keys.Start):
|
||
|
cmd := start_pause_resume(a.pomodoro)
|
||
|
client.SendCmd(cmd)
|
||
|
case key.Matches(msg, a.keys.Stop):
|
||
|
client.SendCmd("stop")
|
||
|
case key.Matches(msg, a.keys.Reset):
|
||
|
if config.PomodoroConfig != (GoTomato.PomodoroConfig{}) {
|
||
|
client.SendSettingsUpdate(config.PomodoroConfig)
|
||
|
}
|
||
|
case key.Matches(msg, a.keys.Quit):
|
||
|
client.Disconnect()
|
||
|
return a, tea.Quit
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return a, nil
|
||
|
}
|