Skip to content

Commit

Permalink
added pomodoro timer, use notify-send directly
Browse files Browse the repository at this point in the history
  • Loading branch information
abenz1267 committed Feb 29, 2024
1 parent 67560d5 commit f42e341
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 59 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
# remindme - quick n stupid desktop reminders
# remindme - quick n stupid desktop reminders and simple pomodoro timer

## Usage

- `remindme in <duration><m/h> <message>`, example: `remindme in 10m This is a message`
- `remindme at <time> <message>`, example: `remindme at 15:32 This is a message`
- `remindme --watch`, starts notifier
- `remindme in <duration><m/h> <message>`, example: `remindme in 10m This is a message`
- `remindme at <time> <message>`, example: `remindme at 15:32 This is a message`
- `remindme p <start/stop>`, example: `remindme at 15:32 This is a message`
- `remindme --watch`, starts notifier

Adding a "!" suffix to the message will create an alert instead of a normal notification.

## Pomodoro

- 25 minutes work
- 5 minute break
- 20 minutes break after 4 working units

## quick n dirty

dont look at the code. it works.
12 changes: 2 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module github.com/abenz1267/remindme

go 1.18
go 1.22

require (
github.com/gen2brain/beeep v0.0.0-20220518085355-d7852edf42fc // indirect
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect
)
require golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
15 changes: 2 additions & 13 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
github.com/gen2brain/beeep v0.0.0-20220518085355-d7852edf42fc h1:6ZZLxG+lB+Qbg+chtzAEeetwqjlPnY0BXbhL3lQWYOg=
github.com/gen2brain/beeep v0.0.0-20220518085355-d7852edf42fc/go.mod h1:/WeFVhhxMOGypVKS0w8DUJxUBbHypnWkUVnW7p5c9Pw=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225 h1:LfspQV/FYTatPTr/3HzIcmiUFH7PGP+OQ6mgDYo3yuQ=
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
147 changes: 115 additions & 32 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,59 +6,83 @@ import (
"log"
"net"
"os"
"os/exec"
"strconv"
"strings"
"time"

"github.com/gen2brain/beeep"
"golang.org/x/exp/slices"
)

type Reminder struct {
Time time.Time `json:"time"`
Message string `json:"message"`
Time time.Time `json:"time"`
Message string `json:"message"`
IsPomodoro bool `json:"is_pomodoro"`
PomodoroNum int `json:"pomodoro_num"`
}

const SockAddr = "/tmp/remindme.sock"
const (
SockAddr = "/tmp/remindme.sock"
UrgencyLow = "low"
UrgencyNormal = "normal"
UrgencyCritical = "critical"
BreakMsg = "5 minute break"
BreakFinishedMsg = "break finished"
LongBreakMsg = "20 minute break"
PomodoroStoppedMsg = "stopped"
PomodoroStartedMsg = "started"
)

var data = []Reminder{}
var (
data = []Reminder{}
pCount = 0
pNum = 0
)

func main() {
args := os.Args[1:]

switch args[0] {
case "in":
r := Reminder{
send(Reminder{
Time: parseTimeIn(args[1]),
Message: strings.Join(args[2:], " "),
}

b, err := json.Marshal(&r)
if err != nil {
log.Panic(err)
}

send(b)
})
case "at":
r := Reminder{
send(Reminder{
Time: parseTimeAt(args[1]),
Message: strings.Join(args[2:], " "),
})
case "p":
switch args[1] {
case "start":
send(Reminder{
Time: time.Now(),
Message: PomodoroStartedMsg,
IsPomodoro: true,
})
case "stop":
send(Reminder{
Time: time.Now(),
Message: PomodoroStoppedMsg,
IsPomodoro: true,
})
default:
fmt.Println("use 'start' or 'stop'")
}

b, err := json.Marshal(&r)
if err != nil {
log.Panic(err)
}

send(b)
case "--watch":
watch()
default:
fmt.Println("use 'in' or 'at'")
fmt.Println("use 'in' or 'at'. Pomodoro with 'p start/stop'")
}
}

func send(b []byte) {
func send(r Reminder) {
b, err := json.Marshal(&r)
if err != nil {
log.Panic(err)
}

conn, err := net.Dial("unix", SockAddr)
if err != nil {
log.Panic(err)
Expand All @@ -83,15 +107,64 @@ func watch() {

for k, v := range data {
if now.After(v.Time) {
if strings.HasSuffix(v.Message, "!") {
err := beeep.Alert("Reminder", strings.TrimSuffix(v.Message, "!"), "assets/warning.png")
if err != nil {
panic(err)
switch v.Message {
case PomodoroStartedMsg:
if v.PomodoroNum == pNum {
pCount = 1

data = append(data, Reminder{
Time: now.Add(time.Second * 25),
Message: BreakMsg,
IsPomodoro: true,
PomodoroNum: pNum,
})

notify("Pomodoro", v.Message, UrgencyNormal)
}
case BreakMsg:
if v.PomodoroNum == pNum {
pause := 5
message := BreakMsg

if pCount == 4 {
message = LongBreakMsg
pause = 20
}

data = append(data, Reminder{
Time: now.Add(time.Second * time.Duration(pause)),
Message: BreakFinishedMsg,
IsPomodoro: true,
PomodoroNum: v.PomodoroNum,
})

notify("Pomodoro", message, UrgencyCritical)
}
} else {
err := beeep.Notify("Reminder", v.Message, "assets/information.png")
if err != nil {
panic(err)
case BreakFinishedMsg:
if v.PomodoroNum == pNum {
pCount++

if pCount > 4 {
pCount = 1
}

data = append(data, Reminder{
Time: now.Add(time.Second * 25),
Message: BreakMsg,
IsPomodoro: true,
PomodoroNum: v.PomodoroNum,
})

notify("Pomodoro", v.Message, UrgencyCritical)
}
case PomodoroStoppedMsg:
pNum++
notify("Pomodoro", v.Message, UrgencyNormal)
default:
if strings.HasSuffix(v.Message, "!") {
notify("Reminder", strings.TrimSuffix(v.Message, "!"), UrgencyCritical)
} else {
notify("Reminder", v.Message, UrgencyNormal)
}
}

Expand All @@ -101,6 +174,16 @@ func watch() {
}
}

// urgency: low, normal, critical
func notify(title, message, urgency string) {
cmd := exec.Command("notify-send", title, message, fmt.Sprintf("--urgency=%s", urgency), "--app-name=RemindMe")

out, err := cmd.CombinedOutput()
if err != nil {
log.Panic(string(out))
}
}

func receive() {
l, err := net.ListenUnix("unix", &net.UnixAddr{Name: SockAddr})
if err != nil {
Expand Down

0 comments on commit f42e341

Please sign in to comment.