Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
ef37747b9d | |||
09452b8c9c | |||
9b7dc19935 | |||
342ecde6bb | |||
c4c787a782 | |||
46c3a4c0b1 | |||
74ee5f3693 | |||
a121f01371 |
9 changed files with 41 additions and 36 deletions
|
@ -15,7 +15,7 @@ The configuration is loaded from `~/config/ChronoTomato.yml`, here is an example
|
||||||
url: ws://localhost:8080/ws
|
url: ws://localhost:8080/ws
|
||||||
password: ""
|
password: ""
|
||||||
config:
|
config:
|
||||||
work: 1500
|
focus: 1500
|
||||||
shortbreak: 300
|
shortbreak: 300
|
||||||
longbreak: 600
|
longbreak: 600
|
||||||
sessions: 4
|
sessions: 4
|
||||||
|
|
|
@ -21,6 +21,8 @@ tasks:
|
||||||
preconditions:
|
preconditions:
|
||||||
- sh: test "{{.BRANCH}}" == "main"
|
- sh: test "{{.BRANCH}}" == "main"
|
||||||
msg: "You must be on the main branch to release"
|
msg: "You must be on the main branch to release"
|
||||||
|
- sh: test -z "$(git status --porcelain)"
|
||||||
|
msg: "You must have a clean working tree to release"
|
||||||
prompt: Create new release {{.RELEASE}} from {{.COMMIT}}@{{.BRANCH}}?
|
prompt: Create new release {{.RELEASE}} from {{.COMMIT}}@{{.BRANCH}}?
|
||||||
cmds:
|
cmds:
|
||||||
- git tag {{.RELEASE}}
|
- git tag {{.RELEASE}}
|
||||||
|
@ -32,3 +34,8 @@ tasks:
|
||||||
desc: Create a local snapshot release
|
desc: Create a local snapshot release
|
||||||
cmds:
|
cmds:
|
||||||
- goreleaser release --clean --snapshot
|
- goreleaser release --clean --snapshot
|
||||||
|
|
||||||
|
install:
|
||||||
|
desc: Install the latest published version locally
|
||||||
|
cmds:
|
||||||
|
- go install git.smsvc.net/pomodoro/ChronoTomato@latest
|
||||||
|
|
|
@ -19,8 +19,8 @@ func desktopNotifications(pomodoro GoTomato.ServerMessage) {
|
||||||
sessions := pomodoro.Settings.Sessions
|
sessions := pomodoro.Settings.Sessions
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case "Work":
|
case "Focus":
|
||||||
duration = pomodoro.Settings.Work
|
duration = pomodoro.Settings.Focus
|
||||||
notification = fmt.Sprintf("Session %d/%d: %s %0.f minutes", session, sessions, mode, float32(duration)/60)
|
notification = fmt.Sprintf("Session %d/%d: %s %0.f minutes", session, sessions, mode, float32(duration)/60)
|
||||||
case "ShortBreak":
|
case "ShortBreak":
|
||||||
duration = pomodoro.Settings.ShortBreak
|
duration = pomodoro.Settings.ShortBreak
|
||||||
|
|
|
@ -43,8 +43,8 @@ func terminalOutput(pomodoro GoTomato.ServerMessage) string {
|
||||||
)
|
)
|
||||||
|
|
||||||
// header
|
// header
|
||||||
output += colour.Sprintf("^D^4Work: %d â—Š Break: %d â—Š Longbreak: %d^R\n\n",
|
output += colour.Sprintf("^D^4Focus: %d â—Š Break: %d â—Š Longbreak: %d^R\n\n",
|
||||||
pomodoro.Settings.Work/60,
|
pomodoro.Settings.Focus/60,
|
||||||
pomodoro.Settings.ShortBreak/60,
|
pomodoro.Settings.ShortBreak/60,
|
||||||
pomodoro.Settings.LongBreak/60,
|
pomodoro.Settings.LongBreak/60,
|
||||||
)
|
)
|
||||||
|
@ -80,8 +80,8 @@ func calc_percentage(message GoTomato.ServerMessage) float64 {
|
||||||
var duration float64
|
var duration float64
|
||||||
|
|
||||||
switch message.Mode {
|
switch message.Mode {
|
||||||
case "Work":
|
case "Focus":
|
||||||
duration = float64(message.Settings.Work)
|
duration = float64(message.Settings.Focus)
|
||||||
case "ShortBreak":
|
case "ShortBreak":
|
||||||
duration = float64(message.Settings.ShortBreak)
|
duration = float64(message.Settings.ShortBreak)
|
||||||
case "LongBreak", "End":
|
case "LongBreak", "End":
|
||||||
|
|
4
go.mod
4
go.mod
|
@ -3,10 +3,10 @@ module git.smsvc.net/pomodoro/ChronoTomato
|
||||||
go 1.23.1
|
go 1.23.1
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.smsvc.net/pomodoro/GoTomato v0.3.1
|
git.smsvc.net/pomodoro/GoTomato v0.5.0
|
||||||
github.com/alecthomas/colour v0.1.0
|
github.com/alecthomas/colour v0.1.0
|
||||||
github.com/charmbracelet/bubbles v0.20.0
|
github.com/charmbracelet/bubbles v0.20.0
|
||||||
github.com/charmbracelet/bubbletea v1.2.2
|
github.com/charmbracelet/bubbletea v1.2.3
|
||||||
github.com/charmbracelet/log v0.4.0
|
github.com/charmbracelet/log v0.4.0
|
||||||
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
|
github.com/gen2brain/beeep v0.0.0-20240516210008-9c006672e7f4
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
|
|
8
go.sum
8
go.sum
|
@ -1,13 +1,13 @@
|
||||||
git.smsvc.net/pomodoro/GoTomato v0.3.1 h1:0YUOqwluUlnx1PLQiXCxRuNwejcE/IkNOD1SuCObyUA=
|
git.smsvc.net/pomodoro/GoTomato v0.5.0 h1:ni6v5iNnSac/Os3skmGobAwjyXP3uS76N+fhZDubqkU=
|
||||||
git.smsvc.net/pomodoro/GoTomato v0.3.1/go.mod h1:LaKrPdnFB5v4RpltExKasW67TmjJlmhDDvmoEYWv0P4=
|
git.smsvc.net/pomodoro/GoTomato v0.5.0/go.mod h1:LaKrPdnFB5v4RpltExKasW67TmjJlmhDDvmoEYWv0P4=
|
||||||
github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=
|
github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk=
|
||||||
github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
|
||||||
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
github.com/charmbracelet/bubbles v0.20.0 h1:jSZu6qD8cRQ6k9OMfR1WlM+ruM8fkPWkHvQWD9LIutE=
|
||||||
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
github.com/charmbracelet/bubbles v0.20.0/go.mod h1:39slydyswPy+uVOHZ5x/GjwVAFkCsV8IIVy+4MhzwwU=
|
||||||
github.com/charmbracelet/bubbletea v1.2.2 h1:EMz//Ky/aFS2uLcKqpCst5UOE6z5CFDGRsUpyXz0chs=
|
github.com/charmbracelet/bubbletea v1.2.3 h1:d9MdMsANIYZB5pE1KkRqaUV6GfsiWm+/9z4fTuGVm9I=
|
||||||
github.com/charmbracelet/bubbletea v1.2.2/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
|
github.com/charmbracelet/bubbletea v1.2.3/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
|
||||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
||||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
||||||
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gorilla/websocket"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client ChronoTomato.GoTomatoClient // New websocket client
|
// New websocket client
|
||||||
|
type Client ChronoTomato.GoTomatoClient
|
||||||
|
|
||||||
// Connects to websocket
|
// Connects to websocket
|
||||||
func Connect(url string) Client {
|
func Connect(url string) Client {
|
||||||
|
@ -16,10 +18,6 @@ func Connect(url string) Client {
|
||||||
return Client{Conn: conn, Server: url, LastErr: err}
|
return Client{Conn: conn, Server: url, LastErr: err}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c Client) Connected() bool {
|
|
||||||
return c.Conn != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Disconnects from websocket
|
// Disconnects from websocket
|
||||||
func (c Client) Disconnect() {
|
func (c Client) Disconnect() {
|
||||||
// Cleanly close the connection by sending a close message and then
|
// Cleanly close the connection by sending a close message and then
|
||||||
|
@ -33,3 +31,7 @@ func (c Client) Disconnect() {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Client) Connected() bool {
|
||||||
|
return c.Conn != nil
|
||||||
|
}
|
||||||
|
|
|
@ -9,12 +9,10 @@ import (
|
||||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Done = make(chan struct{})
|
|
||||||
|
|
||||||
// Receives websocket messages and writes them to a channel.
|
// Receives websocket messages and writes them to a channel.
|
||||||
// Closes the channel if websocket closes.
|
// Closes the channel if websocket closes.
|
||||||
func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
var serverMessage, prevMessage GoTomato.ServerMessage
|
var serverMessage GoTomato.ServerMessage
|
||||||
|
|
||||||
defer close(Done)
|
defer close(Done)
|
||||||
|
|
||||||
|
@ -22,27 +20,22 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
c.Conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
c.Conn.SetReadDeadline(time.Now().Add(10 * time.Second))
|
||||||
_, message, err := c.Conn.ReadMessage()
|
_, message, err := c.Conn.ReadMessage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
c.LastErr = err
|
||||||
|
|
||||||
// On normal closure exit gracefully
|
// On normal closure exit gracefully
|
||||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.LastErr = err
|
// reset connection and reconnect
|
||||||
// Try to reconnect on unexpected disconnect
|
c.Conn = nil
|
||||||
for {
|
|
||||||
channel <- prevMessage // send previous ServerMessage to update view
|
|
||||||
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
|
|
||||||
// reconnect while preserving password
|
|
||||||
pw := c.Password
|
pw := c.Password
|
||||||
|
for !c.Connected() {
|
||||||
|
channel <- serverMessage // send last known ServerMessage to update view
|
||||||
|
time.Sleep(time.Second)
|
||||||
*c = Connect(c.Server)
|
*c = Connect(c.Server)
|
||||||
|
}
|
||||||
c.Password = pw
|
c.Password = pw
|
||||||
|
|
||||||
if c.Connected() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,6 +43,5 @@ func (c *Client) ProcessServerMessages(channel chan<- GoTomato.ServerMessage) {
|
||||||
c.LastErr = err
|
c.LastErr = err
|
||||||
|
|
||||||
channel <- serverMessage
|
channel <- serverMessage
|
||||||
prevMessage = serverMessage
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
4
internal/websocket/vars.go
Normal file
4
internal/websocket/vars.go
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
package websocket
|
||||||
|
|
||||||
|
// Websocket closure
|
||||||
|
var Done = make(chan struct{})
|
Loading…
Reference in a new issue