feat: refactor to use local pointer for ServerMessage
- replace `shared.ServerMessage` with local pomodoro pointer
- update conditions to use `pomodoro` instead of `shared.ServerMessage`
🤖
This commit is contained in:
parent
a61da7d280
commit
98013780da
3 changed files with 24 additions and 23 deletions
|
@ -29,15 +29,16 @@ func Start() {
|
|||
}
|
||||
|
||||
go websocket.ProcessServerMessages(conn)
|
||||
pomodoro := &shared.ServerMessage
|
||||
|
||||
keyboard.Listen(func(key keys.Key) (stop bool, err error) {
|
||||
switch key.String() {
|
||||
case "space":
|
||||
if !shared.ServerMessage.Ongoing {
|
||||
if !pomodoro.Ongoing {
|
||||
websocket.SendCmd(conn, *password, "start")
|
||||
return false, nil
|
||||
}
|
||||
if shared.ServerMessage.Paused {
|
||||
if pomodoro.Paused {
|
||||
websocket.SendCmd(conn, *password, "resume")
|
||||
return false, nil
|
||||
} else {
|
||||
|
|
|
@ -7,31 +7,31 @@ import (
|
|||
)
|
||||
|
||||
func DesktopNotifications() {
|
||||
msg := &shared.ServerMessage
|
||||
|
||||
var duration int
|
||||
var notification string
|
||||
|
||||
mode := msg.Mode
|
||||
session := msg.Session
|
||||
sessions := msg.PomodoroSettings.Sessions
|
||||
pomodoro := &shared.ServerMessage
|
||||
|
||||
switch msg.Mode {
|
||||
mode := pomodoro.Mode
|
||||
session := pomodoro.Session
|
||||
sessions := pomodoro.PomodoroSettings.Sessions
|
||||
|
||||
switch pomodoro.Mode {
|
||||
case "Work":
|
||||
duration = msg.PomodoroSettings.Work
|
||||
duration = pomodoro.PomodoroSettings.Work
|
||||
notification = fmt.Sprintf("Session %d/%d: %s %0.f minutes", session, sessions, mode, float32(duration)/60)
|
||||
case "ShortBreak":
|
||||
duration = msg.PomodoroSettings.ShortBreak
|
||||
duration = pomodoro.PomodoroSettings.ShortBreak
|
||||
notification = fmt.Sprintf("Session %d/%d: Take a %0.f minute break", session, sessions, float32(duration)/60)
|
||||
case "LongBreak":
|
||||
duration = msg.PomodoroSettings.LongBreak
|
||||
duration = pomodoro.PomodoroSettings.LongBreak
|
||||
notification = fmt.Sprintf("Long Break: Take a %0.f minute break", float32(duration)/60)
|
||||
case "End":
|
||||
duration = 0
|
||||
notification = fmt.Sprintf("Pomodoro sessions complete! Great job! 🎉")
|
||||
}
|
||||
|
||||
if msg.TimeLeft == duration { // start of segment
|
||||
if pomodoro.TimeLeft == duration { // start of segment
|
||||
beeep.Alert("🍅 Pomodoro Timer", notification, "")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,29 +9,29 @@ import (
|
|||
func TerminalOutput() {
|
||||
var timerOutput string
|
||||
|
||||
msg := &shared.ServerMessage
|
||||
pomodoro := &shared.ServerMessage
|
||||
|
||||
fmt.Print("\033[H\033[2J") // Clears the screen
|
||||
|
||||
fmt.Printf("Work: %d | Break: %d | Longbreak: %d\n",
|
||||
msg.PomodoroSettings.Work/60,
|
||||
msg.PomodoroSettings.ShortBreak/60,
|
||||
msg.PomodoroSettings.LongBreak/60,
|
||||
pomodoro.PomodoroSettings.Work/60,
|
||||
pomodoro.PomodoroSettings.ShortBreak/60,
|
||||
pomodoro.PomodoroSettings.LongBreak/60,
|
||||
)
|
||||
fmt.Printf("Session: %d/%d\n",
|
||||
msg.Session,
|
||||
msg.PomodoroSettings.Sessions,
|
||||
pomodoro.Session,
|
||||
pomodoro.PomodoroSettings.Sessions,
|
||||
)
|
||||
fmt.Printf("\n▶ %s\n",
|
||||
msg.Mode,
|
||||
fmt.Printf("▶ %s\n",
|
||||
pomodoro.Mode,
|
||||
)
|
||||
|
||||
switch msg.Mode {
|
||||
switch pomodoro.Mode {
|
||||
case "Idle":
|
||||
timerOutput = ""
|
||||
default:
|
||||
minutes := msg.TimeLeft / 60
|
||||
seconds := msg.TimeLeft % 60
|
||||
minutes := pomodoro.TimeLeft / 60
|
||||
seconds := pomodoro.TimeLeft % 60
|
||||
|
||||
timerOutput = fmt.Sprintf("⏳ %02d:%02d", minutes, seconds)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue