Compare commits
No commits in common. "main" and "v0.1.0" have entirely different histories.
19 changed files with 133 additions and 309 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,3 +1 @@
|
||||||
ChronoTomato
|
ChronoTomato
|
||||||
|
|
||||||
dist/
|
|
||||||
|
|
|
@ -1,40 +0,0 @@
|
||||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
|
||||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
|
||||||
|
|
||||||
version: 2
|
|
||||||
|
|
||||||
before:
|
|
||||||
hooks:
|
|
||||||
- go mod tidy
|
|
||||||
|
|
||||||
builds:
|
|
||||||
- goos:
|
|
||||||
- linux
|
|
||||||
goarch:
|
|
||||||
- amd64
|
|
||||||
- arm64
|
|
||||||
env:
|
|
||||||
- CGO_ENABLED=0
|
|
||||||
ldflags:
|
|
||||||
- -s -w -X {{.ModulePath}}/internal/metadata.ChronoTomatoVersion={{.Version}}
|
|
||||||
|
|
||||||
upx:
|
|
||||||
- enabled: true
|
|
||||||
compress: best
|
|
||||||
lzma: true
|
|
||||||
|
|
||||||
changelog:
|
|
||||||
use: gitea
|
|
||||||
|
|
||||||
archives:
|
|
||||||
- format: binary
|
|
||||||
|
|
||||||
release:
|
|
||||||
gitea:
|
|
||||||
owner: pomodoro
|
|
||||||
name: ChronoTomato
|
|
||||||
mode: replace
|
|
||||||
|
|
||||||
gitea_urls:
|
|
||||||
download: http://git.smsvc.net
|
|
||||||
api: http://git.smsvc.net/api/v1
|
|
|
@ -2,11 +2,5 @@
|
||||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||||
"extends": [
|
"extends": [
|
||||||
"local>infrastructure/renovate-config"
|
"local>infrastructure/renovate-config"
|
||||||
],
|
|
||||||
"packageRules": [
|
|
||||||
{
|
|
||||||
"matchManagers": ["gomod"],
|
|
||||||
"semanticCommitType": "chore"
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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:
|
||||||
focus: 1500
|
work: 1500
|
||||||
shortbreak: 300
|
shortbreak: 300
|
||||||
longbreak: 600
|
longbreak: 600
|
||||||
sessions: 4
|
sessions: 4
|
||||||
|
|
41
Taskfile.yml
41
Taskfile.yml
|
@ -1,41 +0,0 @@
|
||||||
# yaml-language-server: $schema=https://taskfile.dev/schema.json
|
|
||||||
#
|
|
||||||
# github.com/go-task/task/v3/cmd/task@latest
|
|
||||||
# Requirements:
|
|
||||||
# github.com/caarlos0/svu@latest
|
|
||||||
# github.com/goreleaser/goreleaser/v2@latest
|
|
||||||
|
|
||||||
version: '3'
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
|
|
||||||
release:
|
|
||||||
desc: Create and publish an new release
|
|
||||||
vars:
|
|
||||||
RELEASE:
|
|
||||||
sh: svu next
|
|
||||||
BRANCH:
|
|
||||||
sh: git branch --show-current
|
|
||||||
COMMIT:
|
|
||||||
sh: git rev-parse --short --verify {{.BRANCH}}
|
|
||||||
preconditions:
|
|
||||||
- sh: test "{{.BRANCH}}" == "main"
|
|
||||||
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}}?
|
|
||||||
cmds:
|
|
||||||
- git tag {{.RELEASE}}
|
|
||||||
- git push
|
|
||||||
- git push origin tag {{.RELEASE}}
|
|
||||||
- goreleaser release --clean
|
|
||||||
|
|
||||||
snapshot:
|
|
||||||
desc: Create a local snapshot release
|
|
||||||
cmds:
|
|
||||||
- goreleaser release --clean --snapshot
|
|
||||||
|
|
||||||
install:
|
|
||||||
desc: Install the latest published version locally
|
|
||||||
cmds:
|
|
||||||
- go install git.smsvc.net/pomodoro/ChronoTomato@latest
|
|
|
@ -2,11 +2,9 @@ package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"github.com/charmbracelet/log"
|
||||||
"os"
|
|
||||||
|
|
||||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/helper"
|
||||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/metadata"
|
|
||||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
"git.smsvc.net/pomodoro/ChronoTomato/internal/websocket"
|
||||||
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
|
@ -52,14 +50,10 @@ func (a app) waitForChannelSignal() tea.Cmd {
|
||||||
func (a app) Init() tea.Cmd {
|
func (a app) Init() tea.Cmd {
|
||||||
client = websocket.Connect(config.URL)
|
client = websocket.Connect(config.URL)
|
||||||
client.Password = config.Password
|
client.Password = config.Password
|
||||||
if client.LastErr != nil {
|
|
||||||
helper.Logger.Fatal(client.LastErr)
|
|
||||||
}
|
|
||||||
|
|
||||||
go client.ProcessServerMessages(a.channel)
|
go client.ProcessServerMessages(a.channel)
|
||||||
|
|
||||||
return tea.Batch(
|
return tea.Batch(
|
||||||
tea.EnterAltScreen,
|
tea.ClearScreen,
|
||||||
a.waitForChannelSignal(),
|
a.waitForChannelSignal(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -68,21 +62,15 @@ func Start() {
|
||||||
var (
|
var (
|
||||||
defaultConfigFile = "~/.config/ChronoTomato.yml"
|
defaultConfigFile = "~/.config/ChronoTomato.yml"
|
||||||
|
|
||||||
parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
|
parameter_url = flag.String("url", "", "GoTomato Server URL (eg ws://localhost:8080/ws)")
|
||||||
parameter_password = flag.String("password", "", "Control password for pomodoro session")
|
parameter_password = flag.String("password", "", "Control password for pomodoro session")
|
||||||
parameter_configfile = flag.String("config", defaultConfigFile, "Path to config file")
|
configfile = flag.String("config", "", "Path to config file")
|
||||||
showVersion = flag.Bool("version", false, "Show Version")
|
|
||||||
)
|
)
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *showVersion {
|
|
||||||
fmt.Printf("ChronoTomato v%v\n", metadata.ChronoTomatoVersion)
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
|
|
||||||
// read passed config file or try to use default config
|
// read passed config file or try to use default config
|
||||||
if *parameter_configfile != defaultConfigFile {
|
if *configfile != "" {
|
||||||
config = helper.ParseConfig(*parameter_configfile)
|
config = helper.ParseConfig(*configfile)
|
||||||
} else {
|
} else {
|
||||||
if helper.FileExists(defaultConfigFile) {
|
if helper.FileExists(defaultConfigFile) {
|
||||||
config = helper.ParseConfig(defaultConfigFile)
|
config = helper.ParseConfig(defaultConfigFile)
|
||||||
|
@ -99,6 +87,6 @@ func Start() {
|
||||||
|
|
||||||
_, err := tea.NewProgram(myApp()).Run()
|
_, err := tea.NewProgram(myApp()).Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.Logger.Fatal("Could not start program:", "msg", err)
|
log.Fatal("Could not start program:", "msg", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package client
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -8,7 +8,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Send desktop notifications on the start of each segment
|
// Send desktop notifications on the start of each segment
|
||||||
func desktopNotifications(pomodoro GoTomato.ServerMessage) {
|
func DesktopNotifications(pomodoro GoTomato.ServerMessage) {
|
||||||
var (
|
var (
|
||||||
duration int
|
duration int
|
||||||
notification string
|
notification string
|
||||||
|
@ -19,8 +19,8 @@ func desktopNotifications(pomodoro GoTomato.ServerMessage) {
|
||||||
sessions := pomodoro.Settings.Sessions
|
sessions := pomodoro.Settings.Sessions
|
||||||
|
|
||||||
switch mode {
|
switch mode {
|
||||||
case "Focus":
|
case "Work":
|
||||||
duration = pomodoro.Settings.Focus
|
duration = pomodoro.Settings.Work
|
||||||
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
|
51
cmd/client/helper/terminal.go
Normal file
51
cmd/client/helper/terminal.go
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
package helper
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/alecthomas/colour"
|
||||||
|
|
||||||
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Return terminal output based on the passed ServerMessage
|
||||||
|
func TerminalOutput(pomodoro GoTomato.ServerMessage) string {
|
||||||
|
var (
|
||||||
|
output string
|
||||||
|
|
||||||
|
modePrefix string
|
||||||
|
timerOutput string
|
||||||
|
)
|
||||||
|
|
||||||
|
// header
|
||||||
|
output += colour.Sprintf("^D^4Work: %d â—Š Break: %d â—Š Longbreak: %d^R\n\n",
|
||||||
|
pomodoro.Settings.Work/60,
|
||||||
|
pomodoro.Settings.ShortBreak/60,
|
||||||
|
pomodoro.Settings.LongBreak/60,
|
||||||
|
)
|
||||||
|
|
||||||
|
//body
|
||||||
|
switch pomodoro.Mode {
|
||||||
|
case "Idle":
|
||||||
|
modePrefix = " "
|
||||||
|
timerOutput = ""
|
||||||
|
default:
|
||||||
|
modePrefix = " "
|
||||||
|
if pomodoro.Paused {
|
||||||
|
modePrefix = " "
|
||||||
|
}
|
||||||
|
minutes := pomodoro.TimeLeft / 60
|
||||||
|
seconds := pomodoro.TimeLeft % 60
|
||||||
|
|
||||||
|
timerOutput = fmt.Sprintf("⏳ %02d:%02d", minutes, seconds)
|
||||||
|
}
|
||||||
|
|
||||||
|
output += fmt.Sprintf("Session: %d/%d\n",
|
||||||
|
pomodoro.Session,
|
||||||
|
pomodoro.Settings.Sessions,
|
||||||
|
)
|
||||||
|
output += fmt.Sprintf("%s %s\n", modePrefix, pomodoro.Mode)
|
||||||
|
output += fmt.Sprintf(timerOutput)
|
||||||
|
|
||||||
|
return output
|
||||||
|
}
|
|
@ -1,93 +1,24 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/alecthomas/colour"
|
"git.smsvc.net/pomodoro/ChronoTomato/cmd/client/helper"
|
||||||
|
|
||||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
"github.com/charmbracelet/bubbles/progress"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var progressBar = progress.New(progress.WithDefaultGradient(), progress.WithoutPercentage())
|
|
||||||
|
|
||||||
func (a app) View() string {
|
func (a app) View() string {
|
||||||
var body string
|
var body string
|
||||||
var serverStatus string
|
|
||||||
|
|
||||||
body = "Waiting for server message..."
|
|
||||||
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
if a.pomodoro != (GoTomato.ServerMessage{}) {
|
||||||
body = terminalOutput(a.pomodoro)
|
body = helper.TerminalOutput(a.pomodoro)
|
||||||
desktopNotifications(a.pomodoro)
|
helper.DesktopNotifications(a.pomodoro)
|
||||||
}
|
} else {
|
||||||
|
body = "Waiting for first server message..."
|
||||||
serverStatus = colour.Sprintf("^D^1%v^R\n", client.LastErr)
|
|
||||||
if client.Connected() && client.LastErr == nil {
|
|
||||||
serverStatus = colour.Sprintf("^D^2connected to %s^R\n", client.Server)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
helpView := a.help.View(a.keys)
|
helpView := a.help.View(a.keys)
|
||||||
height := 10 - strings.Count(body, "\n") - strings.Count(serverStatus, "\n") - strings.Count(helpView, "\n")
|
height := 8 - strings.Count(body, "\n") - strings.Count(helpView, "\n")
|
||||||
|
|
||||||
return body + strings.Repeat("\n", height) + serverStatus + helpView
|
return body + strings.Repeat("\n", height) + helpView
|
||||||
}
|
|
||||||
|
|
||||||
// Return terminal output based on the passed ServerMessage
|
|
||||||
func terminalOutput(pomodoro GoTomato.ServerMessage) string {
|
|
||||||
var (
|
|
||||||
output string
|
|
||||||
|
|
||||||
modePrefix string
|
|
||||||
timerOutput string
|
|
||||||
)
|
|
||||||
|
|
||||||
// header
|
|
||||||
output += colour.Sprintf("^D^4Focus: %d â—Š Break: %d â—Š Longbreak: %d^R\n\n",
|
|
||||||
pomodoro.Settings.Focus/60,
|
|
||||||
pomodoro.Settings.ShortBreak/60,
|
|
||||||
pomodoro.Settings.LongBreak/60,
|
|
||||||
)
|
|
||||||
|
|
||||||
//body
|
|
||||||
switch pomodoro.Mode {
|
|
||||||
case "Idle":
|
|
||||||
modePrefix = " "
|
|
||||||
timerOutput = ""
|
|
||||||
default:
|
|
||||||
modePrefix = " "
|
|
||||||
if pomodoro.Paused {
|
|
||||||
modePrefix = " "
|
|
||||||
}
|
|
||||||
minutes := pomodoro.TimeLeft / 60
|
|
||||||
seconds := pomodoro.TimeLeft % 60
|
|
||||||
|
|
||||||
timerOutput = fmt.Sprintf("⏱ %02d:%02d", minutes, seconds) + "\n"
|
|
||||||
timerOutput += progressBar.ViewAs(calc_percentage(pomodoro))
|
|
||||||
}
|
|
||||||
|
|
||||||
output += fmt.Sprintf("Session: %d/%d\n",
|
|
||||||
pomodoro.Session,
|
|
||||||
pomodoro.Settings.Sessions,
|
|
||||||
)
|
|
||||||
output += fmt.Sprintf("%s %s\n", modePrefix, pomodoro.Mode) + "\n"
|
|
||||||
output += timerOutput
|
|
||||||
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
||||||
func calc_percentage(message GoTomato.ServerMessage) float64 {
|
|
||||||
var duration float64
|
|
||||||
|
|
||||||
switch message.Mode {
|
|
||||||
case "Focus":
|
|
||||||
duration = float64(message.Settings.Focus)
|
|
||||||
case "ShortBreak":
|
|
||||||
duration = float64(message.Settings.ShortBreak)
|
|
||||||
case "LongBreak", "End":
|
|
||||||
duration = float64(message.Settings.LongBreak)
|
|
||||||
}
|
|
||||||
|
|
||||||
timeLeft := float64(message.TimeLeft)
|
|
||||||
return 1.0 - (timeLeft / duration)
|
|
||||||
}
|
}
|
||||||
|
|
15
go.mod
15
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.5.0
|
git.smsvc.net/pomodoro/GoTomato v0.0.4
|
||||||
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.3
|
github.com/charmbracelet/bubbletea v1.1.2
|
||||||
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
|
||||||
|
@ -15,10 +15,9 @@ require (
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||||
github.com/charmbracelet/harmonica v0.2.0 // indirect
|
github.com/charmbracelet/lipgloss v0.13.0 // indirect
|
||||||
github.com/charmbracelet/lipgloss v1.0.0 // indirect
|
github.com/charmbracelet/x/ansi v0.4.0 // indirect
|
||||||
github.com/charmbracelet/x/ansi v0.4.5 // indirect
|
github.com/charmbracelet/x/term v0.2.0 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.1 // indirect
|
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||||
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
|
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
|
||||||
|
@ -35,8 +34,8 @@ require (
|
||||||
github.com/rivo/uniseg v0.4.7 // indirect
|
github.com/rivo/uniseg v0.4.7 // indirect
|
||||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
|
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||||
golang.org/x/sync v0.9.0 // indirect
|
golang.org/x/sync v0.8.0 // indirect
|
||||||
golang.org/x/sys v0.27.0 // indirect
|
golang.org/x/sys v0.26.0 // indirect
|
||||||
golang.org/x/text v0.3.8 // indirect
|
golang.org/x/text v0.3.8 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||||
)
|
)
|
||||||
|
|
30
go.sum
30
go.sum
|
@ -1,23 +1,21 @@
|
||||||
git.smsvc.net/pomodoro/GoTomato v0.5.0 h1:ni6v5iNnSac/Os3skmGobAwjyXP3uS76N+fhZDubqkU=
|
git.smsvc.net/pomodoro/GoTomato v0.0.4 h1:+pCbPXUMtPteQilMe3QNo6fl67kB9gO6C/g0sNj1zck=
|
||||||
git.smsvc.net/pomodoro/GoTomato v0.5.0/go.mod h1:LaKrPdnFB5v4RpltExKasW67TmjJlmhDDvmoEYWv0P4=
|
git.smsvc.net/pomodoro/GoTomato v0.0.4/go.mod h1:rNFUjjBMKplygWYbgErWd4cD8JQ66h0KyiK54cGktJo=
|
||||||
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.3 h1:d9MdMsANIYZB5pE1KkRqaUV6GfsiWm+/9z4fTuGVm9I=
|
github.com/charmbracelet/bubbletea v1.1.2 h1:naQXF2laRxyLyil/i7fxdpiz1/k06IKquhm4vBfHsIc=
|
||||||
github.com/charmbracelet/bubbletea v1.2.3/go.mod h1:Qr6fVQw+wX7JkWWkVyXYk/ZUQ92a6XNekLXa3rR18MM=
|
github.com/charmbracelet/bubbletea v1.1.2/go.mod h1:9HIU/hBV24qKjlehyj8z1r/tR9TYTQEag+cWZnuXo8E=
|
||||||
github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ=
|
github.com/charmbracelet/lipgloss v0.13.0 h1:4X3PPeoWEDCMvzDvGmTajSyYPcZM4+y8sCA/SsA3cjw=
|
||||||
github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao=
|
github.com/charmbracelet/lipgloss v0.13.0/go.mod h1:nw4zy0SBX/F/eAO1cWdcvy6qnkDUxr8Lw7dvFrAIbbY=
|
||||||
github.com/charmbracelet/lipgloss v1.0.0 h1:O7VkGDvqEdGi93X+DeqsQ7PKHDgtQfF8j8/O2qFMQNg=
|
|
||||||
github.com/charmbracelet/lipgloss v1.0.0/go.mod h1:U5fy9Z+C38obMs+T+tJqst9VGzlOYGj4ri9reL3qUlo=
|
|
||||||
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
|
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
|
||||||
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
|
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
|
||||||
github.com/charmbracelet/x/ansi v0.4.5 h1:LqK4vwBNaXw2AyGIICa5/29Sbdq58GbGdFngSexTdRM=
|
github.com/charmbracelet/x/ansi v0.4.0 h1:NqwHA4B23VwsDn4H3VcNX1W1tOmgnvY1NDx5tOXdnOU=
|
||||||
github.com/charmbracelet/x/ansi v0.4.5/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
github.com/charmbracelet/x/ansi v0.4.0/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
||||||
github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
|
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
|
||||||
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
|
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
|
||||||
|
@ -64,12 +62,12 @@ github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG0
|
||||||
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
|
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||||
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
|
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||||
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||||
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
|
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
|
||||||
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
|
||||||
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package helper
|
package helper
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -32,12 +33,12 @@ func ParseConfig(filename string) ChronoTomato.Config {
|
||||||
|
|
||||||
yamlFile, err := os.ReadFile(expandUnixPath(filename))
|
yamlFile, err := os.ReadFile(expandUnixPath(filename))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Fatal("Error opening config file!", "reason", err)
|
log.Fatal("Error opening config file!", "reason", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = yaml.Unmarshal(yamlFile, &config)
|
err = yaml.Unmarshal(yamlFile, &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Logger.Fatalf("Unmarshal: %v", err)
|
log.Fatalf("Unmarshal: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
package helper
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/charmbracelet/log"
|
|
||||||
"os"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
var Logger = log.NewWithOptions(os.Stdout, log.Options{
|
|
||||||
ReportTimestamp: true,
|
|
||||||
TimeFormat: time.RFC3339,
|
|
||||||
})
|
|
|
@ -1,33 +0,0 @@
|
||||||
package metadata
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os/exec"
|
|
||||||
"runtime/debug"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
var ChronoTomatoVersion = "" // The GoTomato version
|
|
||||||
|
|
||||||
func stripVersionPrefix(version string) string {
|
|
||||||
return strings.TrimLeft(version, "v")
|
|
||||||
}
|
|
||||||
|
|
||||||
func getLatestTag() string {
|
|
||||||
bytes, _ := exec.Command("git", "describe", "--tags").Output()
|
|
||||||
output := strings.TrimSpace(string(bytes))
|
|
||||||
return stripVersionPrefix(output)
|
|
||||||
}
|
|
||||||
|
|
||||||
// set GoTomatoVersion from runtime/debug.Main.Version
|
|
||||||
// use latest git tag as fallback
|
|
||||||
// can be overwritten via ldflags (e,g. by goreleaser)
|
|
||||||
func init() {
|
|
||||||
if ChronoTomatoVersion == "" {
|
|
||||||
info, _ := debug.ReadBuildInfo()
|
|
||||||
if info.Main.Version != "(devel)" {
|
|
||||||
ChronoTomatoVersion = stripVersionPrefix(info.Main.Version)
|
|
||||||
} else {
|
|
||||||
ChronoTomatoVersion = getLatestTag()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +1,42 @@
|
||||||
package websocket
|
package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"github.com/charmbracelet/log"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
"time"
|
||||||
|
|
||||||
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
ChronoTomato "git.smsvc.net/pomodoro/ChronoTomato/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// New websocket client
|
type Client ChronoTomato.GoTomatoClient // New websocket client
|
||||||
type Client ChronoTomato.GoTomatoClient
|
|
||||||
|
|
||||||
// Connects to websocket
|
// Connects to websocket
|
||||||
func Connect(url string) Client {
|
func Connect(url string) Client {
|
||||||
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
conn, _, err := websocket.DefaultDialer.Dial(url, nil)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal("Dial error!", "reason", err)
|
||||||
|
}
|
||||||
|
|
||||||
return Client{Conn: conn, Server: url, LastErr: err}
|
log.Info("Connected ó°–ź ", "host", url)
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
|
||||||
|
return Client{Conn: conn}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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
|
select {
|
||||||
// waiting (with timeout) for the server to close the connection.
|
case <-Done:
|
||||||
if c.Connected() {
|
// session closed by remote
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
// Cleanly close the connection by sending a close message and then
|
||||||
|
// waiting (with timeout) for the server to close the connection.
|
||||||
c.Conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
c.Conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||||
select {
|
select {
|
||||||
case <-Done:
|
case <-Done:
|
||||||
case <-time.After(time.Second):
|
case <-time.After(time.Second):
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c Client) Connected() bool {
|
|
||||||
return c.Conn != nil
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,45 +2,39 @@ package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
"github.com/charmbracelet/log"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
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 GoTomato.ServerMessage
|
var serverMessage GoTomato.ServerMessage
|
||||||
|
|
||||||
defer close(Done)
|
defer close(Done)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
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
|
|
||||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||||
|
// Ignore normal closure and exit gracefully
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// Log any other errors
|
||||||
// reset connection and reconnect
|
log.Error("Read error!", "reason", err)
|
||||||
c.Conn = nil
|
close(channel)
|
||||||
pw := c.Password
|
return
|
||||||
for !c.Connected() {
|
|
||||||
channel <- serverMessage // send last known ServerMessage to update view
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
*c = Connect(c.Server)
|
|
||||||
}
|
|
||||||
c.Password = pw
|
|
||||||
continue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(message, &serverMessage)
|
err = json.Unmarshal(message, &serverMessage)
|
||||||
c.LastErr = err
|
if err != nil {
|
||||||
|
log.Error("Error unmarshalling!", "reason", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
channel <- serverMessage
|
channel <- serverMessage
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,32 +2,29 @@ package websocket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
|
||||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Sends a message to the clients websocket
|
// Sends a message to the clients websocket
|
||||||
func sendClientCommand(c *Client, msg GoTomato.ClientCommand) {
|
func sendClientCommand(c Client, msg GoTomato.ClientCommand) {
|
||||||
if !c.Connected() {
|
|
||||||
// noop if client is not connected
|
|
||||||
return
|
|
||||||
}
|
|
||||||
messageBytes, err := json.Marshal(msg)
|
messageBytes, err := json.Marshal(msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.LastErr = err
|
log.Error("Error marshalling!", "reason", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = c.Conn.WriteMessage(websocket.TextMessage, messageBytes)
|
err = c.Conn.WriteMessage(websocket.TextMessage, messageBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.LastErr = err
|
log.Error("Write error!", "reason", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends the passed command to the server
|
// Sends the passed command to the server
|
||||||
func (c *Client) SendCmd(cmd string) {
|
func (c Client) SendCmd(cmd string) {
|
||||||
message := GoTomato.ClientCommand{
|
message := GoTomato.ClientCommand{
|
||||||
Command: cmd,
|
Command: cmd,
|
||||||
Password: c.Password,
|
Password: c.Password,
|
||||||
|
@ -37,7 +34,7 @@ func (c *Client) SendCmd(cmd string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sends the new PomodoroConfig to the server
|
// Sends the new PomodoroConfig to the server
|
||||||
func (c *Client) SendSettingsUpdate(settings GoTomato.PomodoroConfig) {
|
func (c Client) SendSettingsUpdate(settings GoTomato.PomodoroConfig) {
|
||||||
message := GoTomato.ClientCommand{
|
message := GoTomato.ClientCommand{
|
||||||
Command: "updateSettings",
|
Command: "updateSettings",
|
||||||
Password: c.Password,
|
Password: c.Password,
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
package websocket
|
|
||||||
|
|
||||||
// Websocket closure
|
|
||||||
var Done = make(chan struct{})
|
|
|
@ -4,8 +4,6 @@ import "github.com/gorilla/websocket"
|
||||||
|
|
||||||
// Represents a GoTomato client
|
// Represents a GoTomato client
|
||||||
type GoTomatoClient struct {
|
type GoTomatoClient struct {
|
||||||
Server string // The GoTomato server
|
|
||||||
Password string // Pomodoro password
|
|
||||||
Conn *websocket.Conn // The websocket connection of the client
|
Conn *websocket.Conn // The websocket connection of the client
|
||||||
LastErr error // Last client error
|
Password string // Pomodoro password
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue