πŸ“¦ axelbdt / pomodoro

πŸ“„ spec.md Β· 299 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299# Pomodoro Timer - Single Process Specification

## Architecture

Single Go binary. No daemon, no CLI, no socket IPC. One process creates systray icon and manages all timer logic internally.

## Core Flow

```
User runs: ./pomodoro
β†’ Single process starts
β†’ Creates systray icon
β†’ Runs timer loop in goroutine
β†’ User controls via systray menu only
β†’ Process exits when user clicks Quit
```

## Timer Cycle

**3 work sessions per cycle:**
- Work (25min) β†’ Short Break (5min) β†’ Work (25min) β†’ Short Break (5min) β†’ Work (25min) β†’ Long Break (20min) β†’ [repeat]

**Phase transitions:**
- Work completes β†’ Break starts immediately (notification + sound)
- Break completes β†’ Enter WAITING state (notification + sound)
- User activity detected β†’ Next work starts automatically
- Manual start available via menu during WAITING

## State Machine

```
IDLE (0/3)
  ↓ [Start clicked]
WORK (1/3) - 25:00
  ↓ [timer expires]
SHORT_BREAK (1/3) - 5:00
  ↓ [timer expires]
WAITING_WORK (1/3)
  ↓ [activity detected OR Start clicked]
WORK (2/3) - 25:00
  ↓ [timer expires]
SHORT_BREAK (2/3) - 5:00
  ↓ [timer expires]
WAITING_WORK (2/3)
  ↓ [activity detected OR Start clicked]
WORK (3/3) - 25:00
  ↓ [timer expires]
LONG_BREAK (3/3) - 20:00
  ↓ [timer expires]
WAITING_WORK (0/3)  [counter resets]
  ↓ [activity detected OR Start clicked]
WORK (1/3) - 25:00  [cycle repeats]
```

**Pause behavior:**
- Pause available during WORK and BREAK phases only
- Paused timer shows ⏸️ prefix
- Not available during WAITING or IDLE

## Systray UI

### Icon States

4 PNG icons (16x16 or 24x24):
- `idle.png` - Gray circle - shown when IDLE or PAUSED
- `work.png` - Red tomato - shown during WORK
- `break.png` - Green coffee cup - shown during SHORT_BREAK and LONG_BREAK
- `waiting.png` - Yellow hourglass - shown during WAITING_WORK

Icon updates every second based on current phase.

### Title (Panel Text)

**No hover tooltip works reliably.** Title is the only visible text in system panel.

Format patterns:
```
IDLE:           "Pomodoro"
WORK:           "πŸ… 25:00 [1/3]"
SHORT_BREAK:    "β˜• 5:00 [1/3]"
LONG_BREAK:     "🌴 20:00 [3/3]"
WAITING:        "⏳ Ready [1/3]"
PAUSED:         "⏸️ 25:00 [1/3]"
```

Format: `[emoji] [MM:SS] [completed/total]`
- Emoji indicates phase type
- MM:SS shows time remaining (omitted for WAITING/IDLE)
- [N/M] shows session progress
- Paused adds ⏸️ prefix

Updates every second during active timer.

### Context Menu (Right-Click)

Menu structure (static, always present):

```
Start/Resume
Pause
Skip Phase
Reset
─────────────
Quit
```

**Menu item states:**

| State | Start/Resume | Pause | Skip Phase | Reset |
|-------|-------------|-------|------------|-------|
| IDLE | Enabled | Disabled | Disabled | Disabled |
| WORK running | Disabled | Enabled | Enabled | Enabled |
| WORK paused | Enabled | Disabled | Enabled | Enabled |
| BREAK running | Disabled | Enabled | Enabled | Enabled |
| BREAK paused | Enabled | Disabled | Enabled | Enabled |
| WAITING | Enabled | Disabled | Enabled | Enabled |

**Actions:**

- **Start/Resume**: 
  - IDLE β†’ Start first work (1/3)
  - WAITING β†’ Start next work
  - PAUSED β†’ Resume timer
  
- **Pause**: 
  - WORK/BREAK running β†’ Pause timer
  
- **Skip Phase**:
  - WORK β†’ Skip to break (short or long based on session count)
  - BREAK β†’ Skip to WAITING
  - WAITING β†’ Start next work immediately
  
- **Reset**:
  - Any state β†’ IDLE (0/3), clear all progress
  
- **Quit**:
  - Always enabled
  - Exit process (no state persistence)

### Click Behavior

**Left click on icon:** Toggle Start/Pause
- IDLE β†’ Start first work
- WAITING β†’ Start next work
- Running β†’ Pause
- Paused β†’ Resume

**Right click:** Show menu

**Middle click:** None (not reliable)

## Notifications

Use `notify-send` for desktop notifications:

```bash
notify-send -a "Pomodoro" -i "appointment-soon" "Pomodoro Timer" "<message>"
```

**Notification triggers:**

| Event | Message |
|-------|---------|
| Work complete (β†’ short break) | "Work complete! Time for a short break." |
| Work complete (β†’ long break) | "Work complete! Time for a long break." |
| Break complete (β†’ waiting) | "Break over! Move your mouse when ready." |
| Timer paused | "Timer paused" |
| Timer resumed | "Timer resumed" |

## Sound

Embedded WAV files using `go:embed`:

**work.wav** (break β†’ work transition):
- 800Hz sine wave
- 0.3 seconds duration
- 16-bit PCM, 44.1kHz sample rate

**break.wav** (work β†’ break transition):
- 600Hz sine wave  
- 0.5 seconds duration
- 16-bit PCM, 44.1kHz sample rate

Playback priority:
1. Try `paplay <file>` (PulseAudio)
2. Fallback `aplay -q <file>` (ALSA)
3. Silent fail if both unavailable

Extract embedded files to `/tmp/pomodoro-work-<uid>.wav` and `/tmp/pomodoro-break-<uid>.wav` on startup, reuse if exists.

## Activity Detection

Use `xprintidle` to detect user activity during WAITING state.

**Logic:**
- Poll every 500ms while in WAITING state
- Track previous idle time
- Activity detected if: `currentIdle < previousIdle` OR `currentIdle < 1000ms`
- On activity: automatically transition to next work phase
- If xprintidle unavailable: disable auto-start, require manual Start click

## Configuration

TOML file at `~/.config/pomodoro/config.toml`:

```toml
work_minutes = 25
short_break_minutes = 5
long_break_minutes = 20
work_sessions_per_cycle = 3
```

Load on startup. Missing file or invalid values β†’ use defaults above.

No hot-reload: changes require restart.

## File Structure

```
pomodoro/
β”œβ”€β”€ main.go              # Entry point, systray setup
β”œβ”€β”€ timer.go             # Timer state machine and logic
β”œβ”€β”€ config.go            # TOML config loading
β”œβ”€β”€ notify.go            # Notifications and sound
β”œβ”€β”€ activity.go          # xprintidle monitoring
β”œβ”€β”€ ui.go                # Systray menu and updates
β”œβ”€β”€ sounds/
β”‚   β”œβ”€β”€ work.wav
β”‚   └── break.wav
β”œβ”€β”€ icons/
β”‚   β”œβ”€β”€ idle.png
β”‚   β”œβ”€β”€ work.png
β”‚   β”œβ”€β”€ break.png
β”‚   └── waiting.png
β”œβ”€β”€ go.mod
└── README.md
```

## Dependencies

```go
require (
    github.com/getlantern/systray v1.2.2
    github.com/BurntSushi/toml v1.5.0
)
```

System packages:
- `libayatana-appindicator3-dev` (Ubuntu/Debian)
- `xprintidle` (optional, for activity detection)
- `pulseaudio-utils` or `alsa-utils` (for sound)

## Build

```bash
go build -o pomodoro .
```

Single binary output. No installation required - run directly.

## Usage

```bash
# Run (stays in foreground)
./pomodoro

# Run in background
./pomodoro &

# Autostart: create ~/.config/autostart/pomodoro.desktop
[Desktop Entry]
Type=Application
Name=Pomodoro Timer
Exec=/path/to/pomodoro
X-GNOME-Autostart-enabled=true
```

## Edge Cases

**Process killed:** All state lost, no recovery. User restarts from IDLE.

**Activity detection fails:** User must manually click Start in WAITING state.

**Sound playback fails:** Silent, continue timer normally.

**Notification fails:** Silent, continue timer normally.

**Multiple instances:** Each creates own systray icon. No lock file. User's problem.

## Non-Features

- No CLI interface
- No daemon/client architecture
- No state persistence
- No pause during WAITING/IDLE
- No custom notification sounds via config (embedded only)
- No statistics or history tracking
- No system tray tooltip (unreliable, title only)